Exemple #1
0
def register_user(user):
    """Performs the user registration process.

    Returns True if the user has been logged in, false otherwise.
    """
    if not _security.confirmable or _security.login_without_confirmation:
        user.active = True

    # confirmation token depends on having user.id set, which requires
    # the user be committed to the database
    user.save(commit=True)

    confirmation_link, token = None, None
    if _security.confirmable:
        confirmation_link, token = generate_confirmation_link(user)

    user_registered.send(current_app._get_current_object(),
                         user=user,
                         confirm_token=token)

    if config_value('SEND_REGISTER_EMAIL'):
        send_mail(config_value('EMAIL_SUBJECT_REGISTER'),
                  user.email,
                  'welcome',
                  user=user,
                  confirmation_link=confirmation_link)

    if not _security.confirmable or _security.login_without_confirmation:
        login_user(user)
        # login_user will modify the user object if _security.trackable is set,
        # but it will not request a session commit itself when it needs it :/
        after_this_request(_commit)
        return True

    return False
Exemple #2
0
def register_user(_confirmation_link_func=None, **user_data):
    """Register a user."""
    confirmation_link_func = _confirmation_link_func or \
        default_confirmation_link_func
    if user_data.get('password') is not None:
        user_data['password'] = hash_password(user_data['password'])
    user = current_datastore.create_user(**user_data)
    current_datastore.commit()

    token, confirmation_link = None, None
    if current_security.confirmable and user.confirmed_at is None:
        token, confirmation_link = confirmation_link_func(user)

    user_registered.send(current_app._get_current_object(),
                         user=user,
                         confirm_token=token)

    if security_config_value('SEND_REGISTER_EMAIL'):
        send_mail(security_config_value('EMAIL_SUBJECT_REGISTER'),
                  user.email,
                  'welcome',
                  user=user,
                  confirmation_link=confirmation_link)

    return user
Exemple #3
0
def register_user(should_confirm, **kwargs):
    confirmation_link, token = None, None
    kwargs['password'] = encrypt_password(kwargs['password'])
    user = user_datastore.create_user(**kwargs)
    user_datastore.commit()
    flash(gettext('User created successfully'))
    if should_confirm:
        confirmation_link, token = generate_confirmation_link(user)
        do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))
        send_mail(
            config_value('EMAIL_SUBJECT_REGISTER'),
            user.email, 'welcome', user=user, confirmation_link=confirmation_link)
    user_registered.send(app, user=user, confirm_token=token)
Exemple #4
0
def register_user(**kwargs):
    security = current_app.extensions.get('security')
    confirmation_link, token = None, None
    kwargs['password'] = hash_password(kwargs['password'])
    user = g.datastore.create_user(**kwargs)

    if security.confirmable:
        confirmation_link, token = generate_confirmation_link(user)
        flash(*get_message('CONFIRM_REGISTRATION', email=user.email))

    user_registered.send(current_app._get_current_object(),
                         user=user, confirm_token=token)

    if config_value('SEND_REGISTER_EMAIL'):
        send_mail(config_value('EMAIL_SUBJECT_REGISTER'), [user.email],
                  'welcome', user=user, confirmation_link=confirmation_link)

    return user
Exemple #5
0
 def test_user_registered(self, post_user_message):
     user_registered.send(self.app, user='******', confirm_token='blah')
     post_user_message.assert_called_with('user', 'just registered.')
Exemple #6
0
=======
    if not form.validate_on_submit():
        return render_template('security/register.html',
                               register_user_form=form,
                               **_ctx('register'))
>>>>>>> 8919129c95bb1e27e30a925240811cf63e13ece9

    token = None
    user = _datastore.create_user(**form.to_dict())
    _commit()

    if _security.confirmable:
        token = send_confirmation_instructions(user)
        do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))

    user_registered.send(dict(user=user, confirm_token=token),
                         app=app._get_current_object())

    _logger.debug('User %s registered' % user)

<<<<<<< HEAD
        return redirect(_security.post_register_view or
                        _security.post_login_view)
        
        do_flash(form.errors, 'error')
=======
    if not _security.confirmable or _security.login_without_confirmation:
        after_this_request(_commit)
        login_user(user)
>>>>>>> 8919129c95bb1e27e30a925240811cf63e13ece9

    post_register_url = get_url(_security.post_register_view)
Exemple #7
0
 def test_sync_user_called_when_user_registered(self, sync_user):
     user = self.create_user("*****@*****.**", "passwd")
     user_registered.send(self.app, user=user, confirm_token="u")
     sync_user.assert_called_once_with(user)