Exemplo n.º 1
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
Exemplo n.º 2
0
def change_user_password(_reset_password_link_func=None, **user_data):
    """Change user password."""
    reset_password_link_func = _reset_password_link_func or \
        default_reset_password_link_func
    user = user_data['user']
    user.password = None
    if user_data.get('password') is not None:
        user.password = hash_password(user_data['password'])
    current_datastore.put(user)
    if security_config_value('SEND_PASSWORD_CHANGE_EMAIL'):
        reset_password_link = None
        if current_security.recoverable:
            _, reset_password_link = reset_password_link_func(user)
        subject = security_config_value('EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE')
        send_mail(subject, user.email, 'change_notice_rest', user=user,
                  reset_password_link=reset_password_link)
    password_changed.send(current_app._get_current_object(),
                          user=user)
Exemplo n.º 3
0
def change_user_password(_reset_password_link_func=None, **user_data):
    """Change user password."""
    reset_password_link_func = (_reset_password_link_func
                                or default_reset_password_link_func)
    user = user_data["user"]
    user.password = None
    if user_data.get("password") is not None:
        user.password = hash_password(user_data["password"])
    current_datastore.put(user)
    if security_config_value("SEND_PASSWORD_CHANGE_EMAIL"):
        reset_password_link = None
        if current_security.recoverable:
            _, reset_password_link = reset_password_link_func(user)
        subject = security_config_value("EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE")
        send_mail(
            subject,
            user.email,
            "change_notice_rest",
            user=user,
            reset_password_link=reset_password_link,
        )
    password_changed.send(current_app._get_current_object(), user=user)