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 add_admin(username, password): '''add_admin -u username -p password''' if username is None or password is None: print "please add corrrect parameters\nadd_admin -u username -p password" return admin = Admin(email=username, password=sha224(password)) admin.save()
def admin_login(): from ezlog2.model.user import Admin email = request.form.get("username",None) password = request.form.get("password",None) admin = Admin.validate_user(email,sha224(password)) if admin is None: flash(u'Login failed','error') return redirect(url_for('admin.index')) session['admin'] = admin.to_dict() flash(u'login successfully','info') return redirect(url_for('admin.index'))
def admin_login(): from ezlog2.model.user import Admin email = request.form.get("username", None) password = request.form.get("password", None) admin = Admin.validate_user(email, sha224(password)) if admin is None: flash(u'Login failed', 'error') return redirect(url_for('admin.index')) session['admin'] = admin.to_dict() flash(u'login successfully', 'info') return redirect(url_for('admin.index'))
def login(): if(request.method == "GET"): return render_template('login.html') email = request.form.get('email',"") password = sha224(request.form.get('password',"")) user = User.validate_user(email, password) if(user is not None): session['user'] = user flash(u'登入成功','info') return redirect(url_for('main')) else: flash(u'登入失败, 请重试','error') return redirect(url_for('login'))
def login(): if (request.method == "GET"): return render_template('login.html') email = request.form.get('email', "") password = sha224(request.form.get('password', "")) user = User.validate_user(email, password) if (user is not None): session['user'] = user flash(u'登入成功', 'info') return redirect(url_for('main')) else: flash(u'登入失败, 请重试', 'error') return redirect(url_for('login'))
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_auth(self): ok_(Admin.is_valid("fake",sha224("fakeone"))) admin = Admin.validate_user("fake",sha224("fakeone")) eq_(admin.id,self.admin.id)
def setUp(self): self.admin = Admin(email="fake", password=sha224("fakeone")).save()
def test_auth(self): ok_(User.is_valid("fake",sha224("fakeone"))) user = User.validate_user("fake",sha224("fakeone")) eq_(user.nickname,self.user.nickname)
def user_create(email, nickname, pw): return User(email=email, nickname=nickname, password=sha224(pw)).save()