Skip to content

Commit

Permalink
Merge pull request #1532 from RocketChat/registration-secret-url
Browse files Browse the repository at this point in the history
Secret URL registration. Closes #1507
  • Loading branch information
engelgabriel committed Dec 1, 2015
2 parents bf4cd17 + fefab76 commit ae85cf6
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 3 deletions.
16 changes: 15 additions & 1 deletion client/routes/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ FlowRouter.route '/room-not-found/:type/:name',

FlowRouter.route '/fxos',
name: 'firefox-os-install'

action: ->
BlazeLayout.render 'fxOsInstallPrompt'

FlowRouter.route '/register/:hash',
name: 'register-secret-url'
action: (params) ->
if RocketChat.settings.get('Accounts_RegistrationForm') is 'Secret URL'
Meteor.call 'checkRegistrationSecretURL', params.hash, (err, success) ->
if success
Session.set 'loginDefaultState', 'register'
BlazeLayout.render 'main', {center: 'home'}
KonchatNotification.getDesktopPermission()
else
BlazeLayout.render 'blankLayout', { render: 'invalidSecretURL' }
else
BlazeLayout.render 'blankLayout', { render: 'invalidSecretURL' }
3 changes: 3 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Accounts_RegistrationForm_LinkReplacementText": "Registration Form Link Replacement Text",
"Accounts_RegistrationForm_Secret_URL" : "Secret URL",
"Accounts_RegistrationForm_SecretURL" : "Registration Form Secret URL",
"Accounts_RegistrationForm_SecretURL_Description" : "You must provide a random string that will be added to your registration URL. Example: https://demo.rocket.chat/register/[secret_hash]",
"Accounts_RegistrationRequired" : "Registration Required",
"Accounts_RequireNameForSignUp" : "Require Name For Signup",
"Accounts_Enrollment_Email" : "Enrollment E-mail",
Expand Down Expand Up @@ -168,6 +169,8 @@
"Install_FxOs_error" : "Sorry, that did not work as intended! The following error appeared:",
"Install_FxOs_follow_instructions" : "Please confirm the app installation on your device (press \"Install\" when prompted).",
"Invalid_confirm_pass" : "The password confirmation does not match password",
"Invalid_Secret_URL" : "Invalid Secret URL",
"Invalid_secret_URL_message" : "The URL provided is invalid.",
"Invalid_email" : "The e-mail entered is invalid",
"Invalid_name" : "The name must not be empty",
"Invalid_pass" : "The password must not be empty",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Package.onUse(function(api) {

// SERVER METHODS
api.addFiles('server/methods/addOAuthService.coffee', 'server');
api.addFiles('server/methods/checkRegistrationSecretURL.coffee', 'server');
api.addFiles('server/methods/joinDefaultChannels.coffee', 'server');
api.addFiles('server/methods/removeOAuthService.coffee', 'server');
api.addFiles('server/methods/robotMethods.coffee', 'server');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Meteor.methods
checkRegistrationSecretURL: (hash) ->
console.log '[method] checkRegistrationSecretURL'.green, hash
return hash is RocketChat.settings.get 'Accounts_RegistrationForm_SecretURL'
12 changes: 12 additions & 0 deletions packages/rocketchat-theme/assets/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -4055,3 +4055,15 @@ a.github-fork {
.inline-video {
max-height: 200px;
}

.attention-message {
color: white;
padding-top: 50px;
font-size: 24px;

i {
display: block;
margin-bottom: 20px;
font-size: 40px;
}
}
13 changes: 12 additions & 1 deletion packages/rocketchat-ui-login/login/form.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Template.loginForm.helpers
return RocketChat.settings.get 'Layout_Login_Terms'

registrationAllowed: ->
return RocketChat.settings.get('Accounts_RegistrationForm') is 'Public'
return RocketChat.settings.get('Accounts_RegistrationForm') is 'Public' or Template.instance().validSecretURL?.get()

linkReplacementText: ->
return RocketChat.settings.get('Accounts_RegistrationForm_LinkReplacementText')
Expand Down Expand Up @@ -81,6 +81,7 @@ Template.loginForm.events
return

if instance.state.get() is 'register'
formData.secretURL = FlowRouter.getParam 'hash'
Meteor.call 'registerUser', formData, (error, result) ->
RocketChat.Button.reset(button)

Expand Down Expand Up @@ -125,8 +126,13 @@ Template.loginForm.onCreated ->
instance = @
if Meteor.settings.public.sandstorm
@state = new ReactiveVar('sandstorm')
else if Session.get 'loginDefaultState'
@state = new ReactiveVar(Session.get 'loginDefaultState')
else
@state = new ReactiveVar('login')

@validSecretURL = new ReactiveVar(false)

@validate = ->
formData = $("#login-card").serializeArray()
formObj = {}
Expand Down Expand Up @@ -162,7 +168,12 @@ Template.loginForm.onCreated ->
$("#login-card input.error").removeClass "error"
return formObj

if FlowRouter.getParam('hash')
Meteor.call 'checkRegistrationSecretURL', FlowRouter.getParam('hash'), (err, success) =>
@validSecretURL.set true

Template.loginForm.onRendered ->
Session.set 'loginDefaultState'
Tracker.autorun =>
switch this.state.get()
when 'login', 'forgot-password', 'email-verification'
Expand Down
12 changes: 12 additions & 0 deletions packages/rocketchat-ui-master/master/blankLayout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template name="blankLayout">
<section class="full-page">
<div class="wrapper">
<header>
<a class="logo" href="/">
<img src="/images/logo/logo.svg?v=3" />
</a>
</header>
{{> Template.dynamic template=render}}
</div>
</section>
</template>
3 changes: 2 additions & 1 deletion packages/rocketchat-ui-master/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Package.onUse(function(api) {
api.addFiles('master/main.html', 'client');
api.addFiles('master/loading.html', 'client');
api.addFiles('master/error.html', 'client');
api.addFiles('master/blankLayout.html', 'client');

api.addFiles('master/main.coffee', 'client');
});
});
1 change: 1 addition & 0 deletions packages/rocketchat-ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Package.onUse(function(api) {
api.addFiles('views/fxos.html', 'client');
api.addFiles('views/modal.html', 'client');
api.addFiles('views/404/roomNotFound.html', 'client');
api.addFiles('views/404/invalidSecretURL.html', 'client');
api.addFiles('views/app/audioNotification.html', 'client');
api.addFiles('views/app/burguer.html', 'client');
api.addFiles('views/app/home.html', 'client');
Expand Down
8 changes: 8 additions & 0 deletions packages/rocketchat-ui/views/404/invalidSecretURL.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template name="invalidSecretURL">
<div class="content">
<div class="attention-message">
<i class="icon-attention"></i>
{{_ 'Invalid_secret_URL_message'}}
</div>
</div>
</template>
3 changes: 3 additions & 0 deletions server/methods/registerUser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Meteor.methods
if RocketChat.settings.get('Accounts_RegistrationForm') is 'Disabled'
throw new Meteor.Error 'registration-disabled', 'User registration is disabled'

else if RocketChat.settings.get('Accounts_RegistrationForm') is 'Secret URL' and (not formData.secretURL or formData.secretURL isnt RocketChat.settings.get('Accounts_RegistrationForm_SecretURL'))
throw new Meteor.Error 'registration-disabled', 'User registration is only allowed via Secret URL'

userData =
email: formData.email
password: formData.pass
Expand Down

0 comments on commit ae85cf6

Please sign in to comment.