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

Conversation

gerwinbrunner
Copy link

This PR will enable guest on the website to register for new user accounts and have them redirected to a "check your email" page (instead of directly logged in).
Only after they confirmed the email address by clicking on the link sent via email they are able to log in.

I hope this is in a condition for you to use. If you need anything else, please let me know.

Best,
Gerwin

I assume that mail sending is set up correctly.

Settings on the client:

Meteor.startup ->
  AccountsEntry.config
    verifyEmail: true
    verifyEmailRoute: '/checkemail'

Setting you need to set on the server only:

Meteor.startup ->
  console.log "Server started"

  Accounts.config
    sendVerificationEmail: true

  Accounts.urls.verifyEmail = (token) ->
    Meteor.absoluteUrl "verify-email/" + token


  # Make sure only users with validated emails can log in
  Accounts.validateLoginAttempt (attempt) ->
    if attempt.user and attempt.user.emails and not attempt.user.emails[0].verified
      console.log "email not verified"
      return false # the login is aborted
    true

Routes you may need:
(Be aware that you have to also create the templates (not shown here).

Router.map ->

  # SignUp emails
  @route "verifyEmail",
    controller: "AccountController"
    path: "/verify-email/:token"
    action: "verifyEmail"

  @route "verified",
    path: "/verified"
    template: "verified"

  @route "checkemail",
    path: "/checkemail"
    template: "checkemail"

@gerwinbrunner
Copy link
Author

Any comments on this? What do you think about it?

@stakabo
Copy link

stakabo commented Oct 7, 2014

I like this idea.

@chirvo
Copy link

chirvo commented Oct 14, 2014

I like this one too. In fact I'm kind of need this feature for a site I'm writing. Would be nice to have this one in the next release.

@gerwinbrunner
Copy link
Author

Are you planning to add this to the main branch?

@jacksoggetto
Copy link

this part of code:

Accounts.validateLoginAttempt (attempt) ->
if attempt.user and attempt.user.emails and not attempt.user.emails[0].verified
console.log "email not verified"
return false # the login is aborted
true

shows an error when an user tried to register, but the user get registered anyway.

this happens with accounts-entry since it tries to login straight away automatically after registration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants