]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Merge branch 'signup-hooks' into 'develop'
authorChocobozzz <chocobozzz@framasoft.org>
Mon, 25 Nov 2019 10:16:12 +0000 (11:16 +0100)
committerChocobozzz <chocobozzz@framasoft.org>
Mon, 25 Nov 2019 10:16:12 +0000 (11:16 +0100)
(plugins) adding signup scope and init hook, modifying ensureUserRegistrationAllowed allowedParams

See merge request framasoft/peertube/PeerTube!24

client/src/app/+signup/+register/register.component.ts
client/src/app/core/plugins/plugin.service.ts
server/middlewares/validators/users.ts
shared/models/plugins/client-hook.model.ts
shared/models/plugins/plugin-client-scope.type.ts
shared/models/plugins/register-server-setting.model.ts

index d470ef4dcc1830f5f1e1f9ea4bc37f34ee5ffb9a..5a7215516a4127ac9e16961a2568b394a894e50e 100644 (file)
@@ -6,6 +6,7 @@ import { UserRegister } from '@shared/models/users/user-register.model'
 import { FormGroup } from '@angular/forms'
 import { About } from '@shared/models/server'
 import { InstanceService } from '@app/shared/instance/instance.service'
+import { HooksService } from '@app/core/plugins/hooks.service'
 import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
 
 @Component({
@@ -41,6 +42,7 @@ export class RegisterComponent implements OnInit {
     private serverService: ServerService,
     private redirectService: RedirectService,
     private instanceService: InstanceService,
+    private hooks: HooksService,
     private i18n: I18n
   ) {
   }
@@ -60,6 +62,8 @@ export class RegisterComponent implements OnInit {
 
         err => this.notifier.error(err.message)
       )
+
+    this.hooks.runAction('action:signup.register.init', 'signup')
   }
 
   hasSameChannelAndAccountNames () {
@@ -94,10 +98,13 @@ export class RegisterComponent implements OnInit {
     if (this.accordion) this.accordion.toggle('code-of-conduct')
   }
 
-  signup () {
+  async signup () {
     this.error = null
 
-    const body: UserRegister = Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value })
+    const body: UserRegister = await this.hooks.wrapObject(
+      Object.assign(this.formStepUser.value, { channel: this.formStepChannel.value }),
+      'filter:api.signup.registration.create.params'
+    )
 
     this.userService.signup(body).subscribe(
       () => {
index 3af36765af795ed8de83fbac93b4ccd25add3242..52ba4215ab380bfd39444ebc45c1b338d773c950 100644 (file)
@@ -42,7 +42,8 @@ export class PluginService implements ClientHook {
   pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
     common: new ReplaySubject<boolean>(1),
     search: new ReplaySubject<boolean>(1),
-    'video-watch': new ReplaySubject<boolean>(1)
+    'video-watch': new ReplaySubject<boolean>(1),
+    signup: new ReplaySubject<boolean>(1)
   }
 
   translationsObservable: Observable<PluginTranslation>
index 8615de4065eb05516f7fc5174dde53aaaa4c47c8..c78c67a8cd7d389e3c50087840891191dbff7e16 100644 (file)
@@ -283,7 +283,8 @@ const usersVideoRatingValidator = [
 const ensureUserRegistrationAllowed = [
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     const allowedParams = {
-      body: req.body
+      body: req.body,
+      ip: req.ip
     }
 
     const allowedResult = await Hooks.wrapPromiseFun(
index 07ea7eb969f78c69bf3c5a522586c767b8f9cb46..91167ff8c76a56712c94552fb538a88e029345eb 100644 (file)
@@ -38,7 +38,10 @@ export const clientFilterHookObject = {
   'filter:api.search.videos.list.result': true,
   // Filter params/result of the function that fetch video-channels according to the user search
   'filter:api.search.video-channels.list.params': true,
-  'filter:api.search.video-channels.list.result': true
+  'filter:api.search.video-channels.list.result': true,
+
+  // Filter form
+  'filter:api.signup.registration.create.params': true
 }
 
 export type ClientFilterHookName = keyof typeof clientFilterHookObject
@@ -58,7 +61,10 @@ export const clientActionHookObject = {
   'action:search.init': true,
 
   // Fired every time Angular URL changes
-  'action:router.navigation-end': true
+  'action:router.navigation-end': true,
+
+  // Fired when the registration page is being initialized
+  'action:signup.register.init': true
 }
 
 export type ClientActionHookName = keyof typeof clientActionHookObject
index 0c616c5edb08cc637bd31ee92ce6640da9a6d052..1c6d884f0f722b6b2abe39dc96aaf518cf254797 100644 (file)
@@ -1 +1 @@
-export type PluginClientScope = 'common' | 'video-watch' | 'search'
+export type PluginClientScope = 'common' | 'video-watch' | 'search' | 'signup'
index 78c5abd1bca0dad23f8bb8e54d066fff5a2a788f..65a1817054664e84e8e6b930373d131b99a4c406 100644 (file)
@@ -3,7 +3,8 @@ export interface RegisterServerSettingOptions {
   label: string
   type: 'input'
 
-  // If the setting is not private, anyone can view its value
+  // If the setting is not private, anyone can view its value (client code included)
+  // If the setting is private, only server-side hooks can access it
   // Mainly used by the PeerTube client to get admin config
   private: boolean