コード例 #1
0
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")
    req = request.values  # 如果值在里面则取,不在则取空
    login_name = req['login_name'] if "login_name" in req else ""
    login_pwd = req['login_pwd'] if "login_pwd" in req else ""
    login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""

    #后端输入验证
    if login_name is None or len(login_name) < 1:
        return ops_renderErrorJSON(msg="请输入正确的管理员账户名")
    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrorJSON(msg="请正确输入管理员账户密码,并且不能小于6个字符!")
    if login_pwd != login_pwd2:
        return ops_renderErrorJSON(msg="请确认管理员账户密码!")
    #后端数据库信息验证

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrorJSON(msg="此管理员账户名已存在,请重新输入!")

    model_user = User()  #model实例化
    model_user.login_name = login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()

    return ops_renderJSON(msg="注册提交成功,等待审核!")
コード例 #2
0
ファイル: member.py プロジェクト: HuichuanLI/flask-web
def reg():
    if request.method == "GET":
        return render_template("member/reg.html")
    else:
        req = request.values
        nickname = req['nickname'] if "nickname" in req else ""
        login_name = req['login_name'] if "login_name" in req else ""
        login_pwd = req['login_pwd'] if "login_pwd" in req else ""
        login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""
        if login_name is None or len(login_name) < 1:
            return ops_renderErrJSON(msg="请输入正确的登录用户名~~")

        if login_pwd is None or len(login_pwd) < 6:
            return ops_renderErrJSON(msg="请输入正确的登录密码,并且不能小于6个字符~~")

        if login_pwd != login_pwd2:
            return ops_renderErrJSON(msg="请输入正确的确认登录密码~~")

        # 查询user用户名
        user_info = User.query.filter_by(login_name=login_name).first()
        print(user_info)
        if user_info:
            return ops_renderErrJSON(msg="登录用户名已被注册,请换一个~~")
        model_user = User()
        model_user.login_name = login_name
        model_user.nickname = nickname if nickname is not None else login_name
        model_user.login_salt = UserService.geneSalt(8)
        model_user.login_pwd = UserService.genePwd(login_pwd,
                                                   model_user.login_salt)
        model_user.created_time = model_user.updated_time = getCurrentTime()
        db.session.add(model_user)
        db.session.commit()

        return ops_renderJSON(msg="注册成功~~")
コード例 #3
0
def reg():
    if request.method == 'GET':
        return ops_render('member/reg.html')

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    login_pwd2 = req['login_pwd2'] if 'login_pwd2' in req else ''

    if not login_name or len(login_name) < 1:
        return ops_renderErrJSON(msg="Please input correct username!")

    if not login_pwd or len(login_pwd) < 6:
        return ops_renderErrJSON(
            msg="Please input correct password! At least 6 characters!")

    if login_pwd != login_pwd2:
        return ops_renderErrJSON(
            msg="Password not match!Please check and input again!")

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="Username already exist!")

    model_user = User()
    model_user.login_name = login_name
    model_user.nickname = login_name
    model_user.login_salt = UserService.genSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="Register Success!")
コード例 #4
0
def reg():
    if request.method == "GET":
        return render_html("/member/reg.html")

    req = request.values
    login_name = req['log_name'] if 'log_name' in req else ""
    login_pwd = req['log_pwd'] if 'log_pwd' in req else ""
    re_pwd = req['re_pwd'] if 're_pwd' in req else ""

    if len(login_name) < 5:
        return render_error("用户名需长于5个字符")

    if len(login_pwd) < 6:
        return render_error("请输入正确的密码, 不得短于6个字符")

    if login_pwd != re_pwd:
        return render_error("两次密码不一致")

    user_info = User.query.filter_by(login_name=login_name).first()

    if user_info:
        return render_error("用户名已被注册,请更换~")

    now_user = User()
    now_user.login_name = login_name
    now_user.nickname = login_name
    now_user.login_salt = PasswordUtil.gen_salt()
    now_user.login_pwd = PasswordUtil.gen_password(login_pwd,
                                                   now_user.login_salt)
    now_user.created_time = UrlManager.get_current_time()
    db.session.add(now_user)
    db.session.commit()
    return render_json(code=200, msg="注册成功", data={})
コード例 #5
0
ファイル: Account.py プロジェクト: why19970628/order
def set_():
    default_pwd = '******'
    if request.method == 'GET':
        resp_data = {}
        req = request.args
        uid = int(req.get('id', 0))
        user_info = None
        if uid:
            user_info = User.query.filter_by(uid=uid).first()
        resp_data['user_info'] = user_info
        return ops_render("account/set.html", resp_data)

    resp = {'code': 200, 'msg': '操作成功!', 'data': {}}
    req = request.values

    # 获取参数
    id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名!"
        return jsonify(resp)

    if mobile is None or len(mobile) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码!"
        return jsonify(resp)

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱!"
        return jsonify(resp)

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登陆用户名!"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登陆密码!"
        return jsonify(resp)

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名!"
        return jsonify(resp)

    has_in = User.query.filter(User.login_name == login_name,
                               User.uid != id).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该登录名已经存在,请换一个试试!"
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    # 编辑
    if user_info:
        model_user = user_info
    # 新增
    else:
        model_user = User()
        model_user.created_time = getCurrentDate()
        model_user.login_salt = UserService.gene_salt()  # 新增登录密匙

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.email = email
    model_user.login_name = login_name
    # 密码修改,当编辑不改密码时,密码不改变,否则将重新设置
    if login_pwd != default_pwd:
        model_user.login_pwd = UserService.gene_pwd(login_pwd,
                                                    model_user.login_salt)
    model_user.updated_time = getCurrentDate()

    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
コード例 #6
0
def set():
    default_pwd = "******"

    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        user_info = None
        if uid:
            user_info = User.query.filter_by(uid=uid).first()
        resp_data["user_info"] = user_info
        return ops_render("account/set.html", resp_data)

    resp = {"code": 200, "msg": "操作成功~", "data": {}}
    req = request.values

    id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名~"
        return jsonify(resp)

    if mobile is None or len(mobile) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码~"
        return jsonify(resp)

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱~"
        return jsonify(resp)

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录用户名~"
        return jsonify(resp)

    if login_pwd is None or len(email) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录密码~"
        return jsonify(resp)

    has_in = User.query.filter(User.login_name == login_name,
                               User.uid != id).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该登录名已存在,请换一个试试~"
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    if user_info:
        model_user = user_info
    else:
        model_user = User()
        model_user.created_time = get_current_date()
        model_user.login_salt = UserService.gen_salt()

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.email = email
    model_user.login_name = login_name

    if login_pwd != default_pwd:
        if user_info and user_info.uid == 1:
            resp['code'] = -1
            resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名~~"
            return jsonify(resp)

        model_user.login_pwd = UserService.gen_pwd(login_pwd,
                                                   model_user.login_salt)

    model_user.updated_time = get_current_date()
    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
コード例 #7
0
ファイル: account.py プロジェクト: hansonhl/mini_app
def set():
    default_pwd = "******"
    if request.method == "GET":
        # pass user info into template to fill in values of html form
        uid = request.args["uid"] if "uid" in request.args else None
        user_info = User.query.filter_by(uid=uid).first() if uid else None
        ctx = {"user": user_info, "default_pwd": default_pwd}
        return render_template_with_global_vars("account/set.html",
                                                context=ctx)

    elif request.method == "POST":
        # obtain info from form
        uid = int(request.form["uid"]) if "uid" in request.form else 0
        username = request.form[
            "login_name"] if "login_name" in request.form else ""
        pwd = request.form["login_pwd"] if "login_pwd" in request.form else ""
        nickname = request.form[
            "nickname"] if "nickname" in request.form else ""
        mobile = request.form["mobile"] if "mobile" in request.form else ""
        email = request.form["email"] if "email" in request.form else ""
        app.logger.debug("setting info for uid %d, new username %s, pwd %s" %
                         (uid, username, pwd))

        # validate form elements
        if len(nickname) < 1 or len(email) < 1 or len(mobile) < 1:
            empty_items = []
            if len(nickname) < 1:
                empty_items.append("姓名")
            if len(mobile) < 1:
                empty_items.append("手机")
            if len(email) < 1:
                empty_items.append("邮箱")
            if len(username) < 1:
                empty_items.append("登录名")
            if len(pwd) < 1:
                empty_items.append("登录密码")
            msg = "以下内容不能为空:" + "、".join(empty_items)
            return json_error_response(msg)
        if len(pwd) < 6 and uid == 0:
            return json_error_response("您的密码不能短于6个字符!")

        user_info = User.query.filter(User.login_name == username,
                                      User.uid != uid).first()
        if user_info:
            return json_error_response("该用户名已被使用,请使用别的用户名!")

        user_info = User.query.filter_by(uid=uid).first()
        app.logger.debug("uid %d user_info %s" % (uid, user_info))
        new_user = False
        if user_info is None:
            new_user = True
            user_info = User()
            user_info.login_salt = generate_salt()
            user_info.created_time = get_current_time()

        user_info.login_name = username
        user_info.nickname = nickname
        user_info.mobile = mobile
        user_info.email = email
        user_info.updated_time = get_current_time()

        # edit password when it is not default value "*****" (see set.html)
        if pwd != default_pwd:
            user_info.login_pwd = generate_salted_pwd(pwd,
                                                      user_info.login_salt)

        db.session.add(user_info)
        db.session.commit()

        return json_response("账号个人信息编辑成功!", data={})
コード例 #8
0
def set():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        info = None
        if uid:
            info = User.query.filter_by(uid=uid).first()
        resp_data['info'] = info
        return ops_render('account/set.html', resp_data)
    # POST  更新数据库
    resp = {'code': 200, 'msg': "操作成功", 'data': {}}
    # ajax 发送的数据
    req = request.values
    id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的昵称"
        return jsonify(resp)
    if mobile is None or len(mobile) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号"
        return jsonify(resp)
    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱"
        return jsonify(resp)
    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录用户名"
        return jsonify(resp)
    if login_pwd is None or len(login_pwd) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的密码"
        return jsonify(resp)

    is_exsits = User.query.filter(User.login_name == login_name,
                                  User.uid != id).first()
    if is_exsits:
        resp['code'] = -1
        resp['msg'] = "该登录名已经存在,请更换"
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    if user_info:
        model_user = user_info
    else:
        model_user = User()
        model_user.created_time = getCurrentDate()
        model_user.login_salt = UserService.generateSalt()

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.email = email
    model_user.login_name = login_name
    if user_info and user_info.uid == 1:
        resp['code'] = -1
        resp['msg'] = "该用户为Bruce,不允许修改"
        return jsonify(resp)
    model_user.login_pwd = UserService.generatePwd(login_pwd,
                                                   model_user.login_salt)
    model_user.updated_time = getCurrentDate()

    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
コード例 #9
0
def set():
    """
        修改个人信息页面、添加账号信息页面
    """
    default_pwd = "******"
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        info = None  # 因为如果是添加信息,那么上个页面,就不会传回id,所以为None,进入添加账号页面。否则点击编辑就传回id,进入修改信息页面
        if uid:
            info = User.query.filter_by(
                uid=uid).first()  # filter_by不用写类,他会自动区分的
        resp_data['info'] = info  # 统一渲染的 resp_data(json)里面,将user_info放进去
        return ops_render("account/set.html", resp_data)

    resp = {'code': 200, 'msg': u"操作成功", 'data': {}}
    # 获取登录变量
    req = request.values  # 所有的请求变量,放到这个数组里

    id = req['id'] if 'id' in req else 0  # id 是用来判断是增加用户信息,还是修改用户信息
    nickname = req['nickname'] if 'nickname' in req else ''  # 三元表达式
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if nickname is None or len(nickname) < 2 or len(nickname) > 15:  # 进行参数判断
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名"
        return jsonify(resp)  # json 格式的转换

    if mobile is None or not re.match(REGEX_MOBILE, mobile):  # 进行参数判断
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码"
        return jsonify(resp)  # json 格式的转换

    if email is None or not re.match(REGEX_Email, email):  # 进行参数判断
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱"
        return jsonify(resp)  # json 格式的转换

    if login_name is None or not re.match(REGEX_LOGIN_NAME,
                                          login_name):  # 进行参数判断
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录名"
        return jsonify(resp)  # json 格式的转换

    if login_pwd is None or len(login_pwd) < 6 or len(
            login_pwd) > 15:  # 进行参数判断
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录密码"
        return jsonify(resp)  # json 格式的转换

    has_in = User.query.filter(User.login_name == login_name,
                               User.uid != id).first()
    # login_name判断用户是否存在。User.uid != id:这个表明是该用户id不存在,即为增加用户信息。filter支持的方式更多一点。filter_by只能传一个json

    if has_in:  # 如果用户名已经存在了
        resp['code'] = -1
        resp['msg'] = "该登录名已存在,请重新输入"
        return jsonify(resp)  # json 格式的转换

    user_info = User.query.filter_by(
        uid=id).first()  # 判断用户 id是否存在。如果存在,那么 modle_use,就是这个用户的信息。set页面为修改用户信息
    if user_info:
        modle_use = user_info
    else:  # 否则,就是这个uid不存在。那么久为增加用户信息界面
        modle_use = User()
        modle_use.created_time = getCurrentData()  # 增加用户信息时,created_time才改变
        modle_use.login_salt = UserService.geneSalt(
        )  # geneSalt即数据库salt字段, 自定义的加密规则。增加用户信息,才会生成salt

    modle_use.nickname = nickname
    modle_use.mobile = mobile
    modle_use.email = email
    modle_use.login_name = login_name
    if login_pwd != default_pwd:  # 如果传回来的密码value,不是default密码,那么就改密码,反之不改密码。
        modle_use.login_pwd = UserService.genePwd(
            login_pwd, modle_use.login_salt)  # 加密后的密码,就是前面定义的,通过密码和 salt进行加密
        resp['msg'] = "操作成功,登录用户 %s 的密码为:%s" % (login_name, login_pwd)
    modle_use.updated_time = getCurrentData()

    db.session.add(modle_use)  # 数据库添加数据,统一提交
    db.session.commit()
    return jsonify(resp)  # 返回信息,更改成功
コード例 #10
0
ファイル: Account.py プロジェクト: SyJarvis/order_applet
def set():
    default_pwd = "******"
    if request.method == 'GET':
        resp_data = {}
        uid = request.args.get('id', 0)
        user_info = None
        if uid:
            user_info = User.query.filter_by(uid=uid).first()
        resp_data['user_info'] = user_info
        resp_data['default_pwd'] = default_pwd
        return ops_render("account/set.html", resp_data)

    elif request.method == 'POST':

        resp = {'code': 200, 'msg': '操作成功', 'data': {}}
        req = request.values
        id = req['id'] if 'id' in req else None
        nickname = req['nickname'] if 'nickname' in req else None
        mobile = req['mobile'] if 'mobile' in req else None
        email = req['email'] if 'email' in req else None
        login_name = req['login_name'] if 'login_name' in req else None
        login_pwd = req['login_pwd'] if 'login_pwd' in req else None

        # if not all([nickname, mobile, email, login_name, login_pwd]):
        #     resp['code'] = -1
        #     resp['msg'] = '数据不完整,请输入完整再提交'
        #     return jsonify(resp)

        if nickname is None or len(nickname) < 1:
            resp['code'] = -1
            resp['msg'] = "请输入符合规范的姓名"
            return jsonify(resp)

        if mobile is None or len(mobile) < 11:
            resp['code'] = -1
            resp['msg'] = "请输入符合规范的手机号码"
            return jsonify(resp)
        if email is None or len(email) < 1:
            resp['code'] = -1
            resp['msg'] = '请输入符合规范的邮箱'
            return jsonify(resp)
        if login_name is None or len(login_name) < 1:
            resp['code'] = -1
            resp['msg'] = '请输入符合规范的登录名'
            return jsonify(resp)
        if login_pwd is None or len(login_pwd) < 1:
            resp['code'] = -1
            resp['msg'] = '请输入符合规范的登录密码'
            return jsonify(resp)

        has_in = User.query.filter(User.login_name == login_name,
                                   User.uid != id).first()
        if has_in:
            resp['code'] = -1
            resp['msg'] = '该登录名已存在,请换一个'
            return jsonify(resp)

        user_info = User.query.filter_by(uid=id).first()
        if user_info:
            model_user = user_info
        else:
            model_user = User()
            model_user.created_time = getCurrentDate()
            model_user.login_salt = UserService.geneSalt()
        model_user.nickname = nickname
        model_user.mobile = mobile
        model_user.email = email
        model_user.login_name = login_name
        if login_pwd != default_pwd:
            model_user.login_pwd = UserService.genePwd(login_pwd,
                                                       model_user.login_salt)

        model_user.updated_time = getCurrentDate()

        db.session.add(model_user)
        db.session.commit()
        return jsonify(resp)
コード例 #11
0
ファイル: Account.py プロジェクト: baimayi/flask_wechat
def set():
    default_pwd = "******"
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        info = None
        if uid:
            info = User.query.filter_by(uid=uid).first()
        resp_data['info'] = info
        return ops_render("account/set.html", resp_data)

    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values

    id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名~~"
        return jsonify(resp)

    if mobile is None or len(mobile) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码~~"
        return jsonify(resp)

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱~~"
        return jsonify(resp)

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登陆用户名~~"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登陆密码~~"
        return jsonify(resp)

    has_in = User.query.filter(
        User.login_name == login_name, User.uid != id).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该登陆名已存在,换一个试试~~"
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    if user_info:
        model_user = user_info

    else:
        model_user = User()
        model_user.update_time = getCurrentDate()
        model_user.login_salt = UserService.geneSalt()

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.email = email
    model_user.login_name = login_name
    if login_pwd != default_pwd:
        model_user.login_pwd = UserService.genePwd(
            login_pwd, model_user.login_salt)
    model_user.created_time = getCurrentDate()

    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)