Exemplo n.º 1
0
def user():
    url = __check_login('user')
    if url: return redirect(url)
    usererrors = []
    userform = UserForm(prefix="user")
    user = get_user(session['email'])
    if request.method == 'GET':
        # Add default values
        userform.email.data = user.email
        userform.first_name.data = user.short_name
        userform.last_name.data = user.family_name
        userform.alias.data = user.alias
    elif userform.validate_on_submit(): 
        if (validate_login(session['email'], userform.password.data)):
            # Update info
            user.email = userform.email.data
            user.short_name = userform.first_name.data 
            user.family_name = userform.last_name.data
            user.full_name = userform.first_name.data + " " + userform.last_name.data
            user.alias = userform.alias.data if userform.alias.data != "" else None
            if (userform.new_password.data):
                user.password = hash_password(userform.new_password.data)
            save_user(user)
            flash(_(u'Information updated'))
        else:
            usererrors.append(_(u'Invalid password'))
    if userform.errors:
        for key, value in userform.errors.items():
            usererrors.append(key + ': ' + value[0])

    return render_template('user.html', userform=userform, usererrors=usererrors)
Exemplo n.º 2
0
def change_language():
    langform = LanguageForm(prefix="language")
    if langform.validate():
        if not 'language' in session or session['language'] != langform.language.data:
            session['language'] = langform.language.data
            # Also change the user language in the database, to make the change persistent
            if 'email' in session: 
                user = get_user(session['email'])
                user.preferred_language = session['language']
                save_user(user)
    else:
        flash(_(u'Invalid language form') + ': ' + ', '.join((key + ': ' + value[0]) for key, value in langform.errors.items()), 'error')
    return redirect(get_redirect_target())
Exemplo n.º 3
0
def reset(reset_key):
    user = get_user_by_reset_key(reset_key)
    if user is None:
        flash(_(u'Invalid password reset link'), 'error')
        return redirect(url_for('troikas'))
    resetform = ResetForm()
    reseterrors = []
    if resetform.validate_on_submit():
        user.password = hash_password(resetform.password.data)
        user.password_reset_key = None
        user.password_reset_expire = None
        session['email'] = user.email
        save_user(user)
        flash(_(u'Password reset successful, you were logged in'))
        return redirect(url_for('troikas'))
    if resetform.errors:
        for key, value in resetform.errors.items():
            reseterrors.append(key + ': ' + value[0])

    return render_template('reset.html', resetform=resetform, reseterrors=reseterrors)