def login(): """ 用户登录视图 :return: """ if request.method == "GET": return render_template("home/login.html") elif request.method == "POST": username = request.json["username"] password = request.json["password"] yzCode = request.json["yzCode"] try: session_yzCode = session["yzCode"] if getPasswordMd5(yzCode.lower(), "O(@(#@EJW@!JIEW") != session_yzCode: session.pop("yzCode", None) return jsonify({"status": "yzcode", "msg": "验证码错误"}) except: return jsonify({"status": "yzcode", "msg": "验证码错误"}) if isEmailString(username): #email形式登录 users = Users.query.filter_by(email=username).first() else: users = Users.query.filter_by(username=username).first() if users != None: password_md5 = getPasswordMd5(password, users.regDate) if password_md5 == users.password: #登录成功 login_user(users) session.permanent = True return jsonify({ "status": "success", "url": url_for("homes.index") }) return jsonify({"status": "failed", "msg": "用户名或密码错误"})
def login(): """ 用户登录视图 :return: """ if request.method == "GET": return render_template("home/login.html") elif request.method == "POST": username = request.json["username"] password = request.json["password"] yzCode = request.json["yzCode"] try: session_yzCode = session["yzCode"] if getPasswordMd5(yzCode.lower(), "O(@(#@EJW@!JIEW") != session_yzCode: session.pop("yzCode", None) return jsonify({"status":"yzcode", "msg":"验证码错误"}) except: return jsonify({"status":"yzcode", "msg":"验证码错误"}) if isEmailString(username): #email形式登录 users = Users.query.filter_by(email=username).first() else: users = Users.query.filter_by(username=username).first() if users != None: password_md5 = getPasswordMd5(password,users.regDate) if password_md5 == users.password:#登录成功 login_user(users) session.permanent = True return jsonify({"status":"success","url":url_for("homes.index")}) return jsonify({"status":"failed", "msg":"用户名或密码错误"})
def register(): """ 用户注册视图 :return: """ if request.method == "GET": return render_template("home/register.html") elif request.method == "POST": inviteCode = request.json['invitecode'] username = request.json['username'] password = request.json['password'] email = request.json['email'] if not isEmailString(email): return jsonify({"stauts":"failed", "msg":"请输入正确的邮箱"}) regDate = getTimeNow() try: invicode = InviteCodeList.query.filter_by(inviteCode=inviteCode).first() if invicode.codestatus == True: try: users = Users(email, username, getPasswordMd5(password,str(regDate)), regDate) db.session.add(users) #db.session.commit() #邀请码失效 invicode.codestatus = False db.session.commit() return jsonify({"status":"success", "url": url_for("homes.login")}) except: return jsonify({"status":"failed", "msg":"填写的信息有误"}) else: return jsonify({"status":"failed", "msg":"邀请码已被使用"}) except: return jsonify({"status":"failed", "msg":"邀请码有误"})
def randomcode(rand): """ 验证码视图 :param rand: :return: """ if request.method == "GET": validcode = ValidCode() code_img, strs = validcode.drawCode() #验证码 session['yzCode'] = getPasswordMd5(strs.lower(), "O(@(#@EJW@!JIEW") buf = StringIO.StringIO() code_img.save(buf, 'JPEG', quality=70) buf_str = buf.getvalue() response = app.make_response(buf_str) response.headers['Content-Type'] = 'image/jpeg' return response
def randomcode(rand): """ 验证码视图 :param rand: :return: """ if request.method == "GET": validcode = ValidCode() code_img, strs = validcode.drawCode() #验证码 session['yzCode'] = getPasswordMd5(strs.lower(), "O(@(#@EJW@!JIEW") buf = StringIO.StringIO() code_img.save(buf,'JPEG',quality=70) buf_str = buf.getvalue() response = app.make_response(buf_str) response.headers['Content-Type'] = 'image/jpeg' return response
def login(): """ 登录函数 v0.1 升级:限制登录次数 :return: """ if request.method == "GET": logout_user() return render_template('admins/login.html') if request.method == "POST": username = request.json['username'] password = request.json['password'] if username != "" and password != "": user = Users.query.filter_by(username=username).first() if user is not None: if user.password == getPasswordMd5(password,user.regDate): login_user(user) session.permanent = True #session有效时间 return jsonify({'url': url_for('admins.index'), 'msg': 'success'}) return jsonify({'msg': 'failed'})
def register(): """ 用户注册视图 :return: """ if request.method == "GET": return render_template("home/register.html") elif request.method == "POST": inviteCode = request.json['invitecode'] username = request.json['username'] password = request.json['password'] email = request.json['email'] if not isEmailString(email): return jsonify({"stauts": "failed", "msg": "请输入正确的邮箱"}) regDate = getTimeNow() try: invicode = InviteCodeList.query.filter_by( inviteCode=inviteCode).first() if invicode.codestatus == True: try: users = Users(email, username, getPasswordMd5(password, str(regDate)), regDate) db.session.add(users) #db.session.commit() #邀请码失效 invicode.codestatus = False db.session.commit() return jsonify({ "status": "success", "url": url_for("homes.login") }) except: return jsonify({"status": "failed", "msg": "填写的信息有误"}) else: return jsonify({"status": "failed", "msg": "邀请码已被使用"}) except: return jsonify({"status": "failed", "msg": "邀请码有误"})
def login(): """ 登录函数 v0.1 升级:限制登录次数 :return: """ if request.method == "GET": logout_user() return render_template('admins/login.html') if request.method == "POST": username = request.json['username'] password = request.json['password'] if username != "" and password != "": user = Users.query.filter_by(username=username).first() if user is not None: if user.password == getPasswordMd5(password, user.regDate): login_user(user) session.permanent = True #session有效时间 return jsonify({ 'url': url_for('admins.index'), 'msg': 'success' }) return jsonify({'msg': 'failed'})