Exemplo n.º 1
0
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":"邀请码有误"})
Exemplo n.º 2
0
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": "邀请码有误"})
Exemplo n.º 3
0
 def isTimeOut(*args, **kwargs):
     if session.get('user') is not None:
         user = session.get('user')
         if getTimeNow() - user['loginTime'] > 600:
             return redirect(url_for('admins.logout'))
     return func(*args, **kwargs)
Exemplo n.º 4
0
 def isTimeOut(*args, **kwargs):
     if session.get('user') is not None:
         user = session.get('user')
         if getTimeNow() - user['loginTime'] > 600:
             return redirect(url_for('admins.logout'))
     return func(*args,**kwargs)