Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force new users to confirm email before allowing them to log in #296

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .versions
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: default
username: Differential
repo: accounts-entry
desc: Meteor sign up and sign in pages.
version: 0.9.0
version: 1.0.3-2

---

Expand Down
7 changes: 6 additions & 1 deletion client/entry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ AccountsEntry =
extraSignUpFields: []
showOtherLoginServices: true

hooks:
afterSignUpHook: (newUserId)->
console.log "afterSignUp hook", newUserId

isStringEmail: (email) ->
emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i
if email.match emailPattern then true else false
Expand All @@ -29,11 +33,12 @@ AccountsEntry =
extraCondition ?= true
unless Meteor.loggingIn()
if Meteor.user() and extraCondition
router.next()
#router.next()
else
Session.set('fromWhere', router.url)
Router.go('/sign-in')
Session.set('entryError', t9n('error.signInRequired'))
#router.next()

@AccountsEntry = AccountsEntry

Expand Down
10 changes: 10 additions & 0 deletions client/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ UI.registerHelper 'passwordLoginService', ->

UI.registerHelper 'showCreateAccountLink', ->
return !Accounts._options.forbidClientAccountCreation


class @Helper
@disableBtns = ($btns) ->
$btns.html($btns.html()+' <i class="fa fa-spinner fa-animate"></i>')
$btns.attr("disabled", "disabled")

@enableBtns = ($btns) ->
$btns.html(_.strLeft($btns.html(),' <i class="fa fa-spinner fa-animate"></i>'))
$btns.attr("disabled", null)
17 changes: 15 additions & 2 deletions client/views/forgotPassword/forgotPassword.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ Template.entryForgotPassword.helpers
Template.entryForgotPassword.events
'submit #forgotPassword': (event) ->
event.preventDefault()
Session.set('email', $('input[name="forgottenEmail"]').val())
Session.set('entryError', null)

email = $('input[name="forgottenEmail"]').val()
if (AccountsEntry.isStringEmail(email) and AccountsEntry.settings.emailToLower) or
(not AccountsEntry.isStringEmail(email) and AccountsEntry.settings.usernameToLower)
email = email.toLowerCase()

Session.set('email', email)
$btns = $(event.target).find("button[type='submit']")
Helper.disableBtns($btns)

if Session.get('email').length is 0
Session.set('entryError', 'Email is required')

Helper.enableBtns($btns)
return

Accounts.forgotPassword({
Expand All @@ -19,5 +30,7 @@ Template.entryForgotPassword.events
if error
Session.set('entryError', error.reason)
else
Router.go AccountsEntry.settings.homeRoute
Router.go AccountsEntry.settings.resetPasswordSuccessRoute

Helper.enableBtns($btns)
)
9 changes: 8 additions & 1 deletion client/views/resetPassword/resetPassword.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Template.entryResetPassword.events

'submit #resetPassword': (event) ->
event.preventDefault()
$btns = $(event.target).find("button[type='submit']")
Helper.disableBtns($btns)

password = $('input[type="password"]').val()

passwordErrors = do (password)->
Expand All @@ -30,11 +33,15 @@ Template.entryResetPassword.events

return false

if passwordErrors then return
if passwordErrors
Helper.enableBtns($btns)
return

Accounts.resetPassword Session.get('resetToken'), password, (error) ->
if error
Session.set('entryError', (error.reason || "Unknown error"))
else
Session.set('resetToken', null)
Router.go AccountsEntry.settings.dashboardRoute

Helper.enableBtns($btns)
5 changes: 5 additions & 0 deletions client/views/signIn/signIn.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ AccountsEntry.entrySignInEvents = {
'submit #signIn': (event) ->
event.preventDefault()

$btns = $(event.target).find("button[type='submit']")
Helper.disableBtns($btns)

email = $('input[name="email"]').val()
if (AccountsEntry.isStringEmail(email) and AccountsEntry.settings.emailToLower) or
(not AccountsEntry.isStringEmail(email) and AccountsEntry.settings.usernameToLower)
Expand All @@ -47,6 +50,8 @@ AccountsEntry.entrySignInEvents = {
Session.set('fromWhere', undefined)
else
Router.go AccountsEntry.settings.dashboardRoute

Helper.enableBtns($btns)
)
}

Expand Down
20 changes: 19 additions & 1 deletion client/views/signUp/extraSignUpFields.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ Template.entryExtraSignUpFields.helpers

Template._entryExtraSignUpField.helpers
isTextField: ->
@type isnt "check_box"
@type isnt "check_box" and @type isnt "select_box"

isCheckbox: ->
@type is "check_box"

isSelectbox: ->
@type is "select_box"



# Added by GB
Template.entryExtraSignUpFields.events
'change select.languageCode': (evt) ->
newLang = $(evt.target).val();
console.log "Template.entryExtraSignUpFields.events","change languageCode", newLang
i18n.setLanguage(newLang)

Template.entryExtraSignUpFields.rendered = ->
$select = $("select.languageCode")
if $select
$("select.languageCode").val(i18n.getLanguage())

6 changes: 6 additions & 0 deletions client/views/signUp/extraSignUpFields.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
{{check_box name label=label required=required}}
</div>
{{/if}}

{{#if isSelectbox}}
<div class="selectbox">
{{select_box field class=field optionValues=optionValues type=type label=label required=required}}
</div>
{{/if}}
</template>
41 changes: 30 additions & 11 deletions client/views/signUp/signUp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ AccountsEntry.entrySignUpEvents = {
'submit #signUp': (event, t) ->
event.preventDefault()

$btns = $(event.target).find("button[type='submit']")
Helper.disableBtns($btns)


username =
if t.find('input[name="username"]')
t.find('input[name="username"]').value.toLowerCase()
Expand Down Expand Up @@ -103,7 +107,9 @@ AccountsEntry.entrySignUpEvents = {

return false

if passwordErrors then return
if passwordErrors
Helper.enableBtns($btns)
return

emailRequired = _.contains([
'USERNAME_AND_EMAIL',
Expand All @@ -115,18 +121,22 @@ AccountsEntry.entrySignUpEvents = {

if usernameRequired && username.length is 0
Session.set('entryError', t9n("error.usernameRequired"))
Helper.enableBtns($btns)
return

if username && AccountsEntry.isStringEmail(username)
Session.set('entryError', t9n("error.usernameIsEmail"))
Helper.enableBtns($btns)
return

if emailRequired && email.length is 0
Session.set('entryError', t9n("error.emailRequired"))
Helper.enableBtns($btns)
return

if AccountsEntry.settings.showSignupCode && signupCode.length is 0
Session.set('entryError', t9n("error.signupCodeRequired"))
Helper.enableBtns($btns)
return


Expand All @@ -137,28 +147,37 @@ AccountsEntry.entrySignUpEvents = {
email: email
password: AccountsEntry.hashPassword(password)
profile: filteredExtraFields
Meteor.call 'entryCreateUser', newUserData, (err, data) ->
Meteor.call 'entryCreateUser', newUserData, (err, newUserId) ->
if err
console.log err
T9NHelper.accountsError err
Helper.enableBtns($btns)
return

AccountsEntry.hooks.afterSignUpHook(newUserId)

#login on client
isEmailSignUp = _.contains([
'USERNAME_AND_EMAIL',
'EMAIL_ONLY'], AccountsEntry.settings.passwordSignupFields)
userCredential = if isEmailSignUp then email else username
Meteor.loginWithPassword userCredential, password, (error) ->
if error
console.log error
T9NHelper.accountsError error
else if Session.get 'fromWhere'
Router.go Session.get('fromWhere')
Session.set 'fromWhere', undefined
else
Router.go AccountsEntry.settings.dashboardRoute

if AccountsEntry.settings.verifyEmail
Router.go AccountsEntry.settings.verifyEmailRoute
else
Meteor.loginWithPassword userCredential, password, (error) ->
if error
console.log error
T9NHelper.accountsError error
else if Session.get 'fromWhere'
Router.go Session.get('fromWhere')
Session.set 'fromWhere', undefined
else
Router.go AccountsEntry.settings.dashboardRoute
else
console.log err
Session.set 'entryError', t9n("error.signupCodeIncorrect")
Helper.enableBtns($btns)
return
}

Expand Down
4 changes: 2 additions & 2 deletions client/views/signUp/signUp.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ <h3>{{t9n "createAccount"}}</h3>
{{/if}}
{{#if both}}
<p class="entry-agreement">{{t9n "clickAgree"}}
<a href="{{privacyUrl}}">{{t9n "privacyPolicy"}}</a> {{t9n "and"}}
<a href="{{termsUrl}}">{{t9n "terms"}}</a>.
<a target="_blank" href="{{privacyUrl}}">{{t9n "privacyPolicy"}}</a> {{t9n "and"}}
<a target="_blank" href="{{termsUrl}}">{{t9n "terms"}}</a>.
</p>
{{else}}
{{#unless neither}}
Expand Down
17 changes: 10 additions & 7 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Package.describe({
summary: "Make signin and signout their own pages with routes.",
version: '1.0.0',
name: "joshowens:accounts-entry",
githubUrl: 'https://github.com/Differential/accounts-entry',
});
version: '1.0.3-5',
name: "vilango:accounts-entry"
});

Package.onUse(function(api) {
api.versionsFrom("[email protected].0");
api.versionsFrom("[email protected].2");

api.use(['iron:[email protected]', 'softwarerero:[email protected]', 'joshowens:[email protected]'], ['client', 'server']);
api.use([
'iron:[email protected]',
'softwarerero:[email protected]',
'joshowens:[email protected]'
], ['client', 'server']);
// CLIENT
api.use([
'deps',
Expand Down Expand Up @@ -89,7 +92,7 @@ Package.onTest(function (api) {
'coffeescript'
]);
api.use(['iron:router', 'softwarerero:accounts-t9n', 'joshowens:simple-form'], ['client', 'server']);
api.use('joshowens:accounts-entry');
api.use('vilango:accounts-entry');

api.addFiles(['tests/route.coffee', 'tests/client.html', 'tests/client.coffee'], 'client');
});
4 changes: 4 additions & 0 deletions server/entry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ Meteor.startup ->
password: user.password
profile: _.extend(profile, user.profile)
if (user.email && Accounts._options.sendVerificationEmail)
@unblock()
Accounts.sendVerificationEmail(userId, user.email)

return userId

Loading