def register(): if(request.method == 'GET'): return render_template('register.html') error = False email = request.form.get('email',None) or None if email is None: flash(u'请输入Email地址','error') error = True if(User.is_email_exist(email)): flash(u'该Email已经注册','error') error = True nickname = request.form.get('nickname',None) or None if nickname is None: flash(u'请输入你的昵称','error') error = True if(User.is_nickname_exist(nickname)): flash(u'该昵称已经注册','error') error = True password = request.form.get('password',None) or None if password is None: flash(u'请输入你的密码','error') error = True if(error): return redirect(url_for('register')) user = User(email=email,nickname=nickname, password=sha224(password)) user.save() flash(u'注册成功','info') session['user'] = user return redirect(url_for('main'))
def register(): if (request.method == 'GET'): return render_template('register.html') error = False email = request.form.get('email', None) or None if email is None: flash(u'请输入Email地址', 'error') error = True if (User.is_email_exist(email)): flash(u'该Email已经注册', 'error') error = True nickname = request.form.get('nickname', None) or None if nickname is None: flash(u'请输入你的昵称', 'error') error = True if (User.is_nickname_exist(nickname)): flash(u'该昵称已经注册', 'error') error = True password = request.form.get('password', None) or None if password is None: flash(u'请输入你的密码', 'error') error = True if (error): return redirect(url_for('register')) user = User(email=email, nickname=nickname, password=sha224(password)) user.save() flash(u'注册成功', 'info') session['user'] = user return redirect(url_for('main'))
def basic_setting(): original_password = request.form.get("original_password", "") user = session['user'] error = False if user.password != sha224(original_password): flash(u"用户ID与密码不匹配",'error') return redirect(url_for("setting_view")) email = request.form.get("email", None) or None if email is None: flash(u'请输入Email地址','error') error = True if(user.email!=email and User.is_email_exist(email)): flash(u'该Email已经注册','error') error = True nickname = request.form.get('nickname',None) or None if nickname is None: flash(u'请输入你的昵称','error') error = True if(user.nickname!=nickname and User.is_nickname_exist(nickname)): flash(u'该昵称已经注册','error') error = True if error: return redirect(url_for("setting_view")) new_pwd = request.form.get("new_password") user.email = email user.nickname = nickname if new_pwd: user.password = sha224(new_pwd) user.save() flash(u"修改成功",'info') session['user'] = user return redirect(url_for("setting_view"))
def test_email_exist(self): ok_(User.is_email_exist("fake")) ok_(not User.is_email_exist("fake1"))