Beispiel #1
0
def user_register():
    form = RegisterForm(request.form)
     
    if not request.method == 'POST' or not form.validate():        
        return render_template("register.html", form = form)
    
    users = dba.select_data(User,name = form.name.data, email = form.email.data)
    if users:
        print "User already exists."
        return redirect(url_for("user_register"))
    
    dba.save_objs(User(name = form.name.data, email = form.email.data))
    return redirect(url_for("login"))
Beispiel #2
0
def user_edit():
    form = LoginEditForm(request.form)
    if request.method == "POST" and form.validate():    
        g.user.email = form.email.data
        g.user.about_me = form.about_me.data
        dba.save_objs(g.user)
        flash('Your changes have been saved.')
        return redirect(url_for('user_edit'))
    else:
        form.email.data = g.user.email
        form.about_me.data = g.user.about_me
    
    return render_template('user_edit.html',
        form = form)
Beispiel #3
0
def login():
    form = LoginForm(request.form)
    
    if request.method == "POST" and form.validate():
        user_query = dba.get_tabel_query(User, email = form.email.data, password = form.password.data)
        user = user_query.first()
                
        if not user:
            flash(u"用户名或密码错误")
            return redirect(url_for("login"))
        
        login_user(user, remember=form.remember_me.data)
        dba.save_objs(g.user)
        return redirect(url_for("index"))
    
    return render_template("login.html", form = form)
Beispiel #4
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        ismanager = 0
        if form.role.data:
            ismanager = 1

        user = User(form.username.data, form.email.data, form.password.data, form.confirm.data, ismanager, form.about_me.data, g.user.last_seen)
        
        try:
            dba.save_objs(user)
        except Exception,e:
            dba.close()
            raise Exception(e)
                
        flash(u'注册成功')
        return redirect(url_for('login'))