Example #1
0
def register():
    if request.method == "GET":
        return ops_render("SignIn/register.html")

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

    username = req['username'] if 'username' in req else ''
    nickname = req['nickname'] if 'nickname' in req else ''
    password = req['password'] if 'password' in req else ''
    email = req['email'] if 'email' in req else ''

    User_info = User.query.filter_by(login_name=username).first()
    if User_info:
        resp['code'] = -1
        resp['msg'] = "已有此账号!"
        return jsonify(resp)

    salt = UserService.geneSalt()
    print(salt)
    password = UserService.genePwd(password, salt)

    model_User_info = User()
    model_User_info.created_time = getCurrentDate()
    model_User_info.login_name = username
    model_User_info.nickname = nickname
    model_User_info.login_salt = salt
    model_User_info.login_pwd = password
    model_User_info.email = email
    model_User_info.updated_time = getCurrentDate()
    db.session.add(model_User_info)
    db.session.commit()
    return jsonify(resp)
Example #2
0
def customesignin():
    default_pwd = "********"

    resp = {'code': 200, 'msg': '注册成功'}
    CustomerPhone = request.values['CustomerPhone'] if 'CustomerPhone' in request.values else -1

    check = CustomerLogin.query.filter_by(CustomerPhone=CustomerPhone).first()
    if check:
        resp['code'] = -1
        resp['msg'] = '手机号已注册'
        return jsonify(resp)

    CustomerPassword = request.values['CustomerPassword'] if 'CustomerPassword' in request.values else -1
    CustomerPayword = request.values['CustomerPayword'] if 'CustomerPayword' in request.values else -1

    signup = CustomerLogin()

    signup.CustomerPhone = CustomerPhone

    signup.Password_salt = UserService.geneSalt()
    if default_pwd != CustomerPassword:
        signup.CustomerPassword = UserService.genePwd(CustomerPassword, signup.Password_salt)

    signup.Payword_salt = UserService.geneSalt()
    if default_pwd != CustomerPassword:
        signup.CustomerPayword = UserService.genePwd(CustomerPayword, signup.Payword_salt)

    signup.created_time = getCurrentDate()
    signup.openid = -1
    Cid = signup.Cid
    db.session.add(signup)
    db.session.commit()

    addinfo = Customer()

    addinfo.Cid = Cid
    addinfo.CustomerName = request.values['CustomerName'] if 'CustomerName' in request.values else '未知名字'
    addinfo.CustomerPhone = CustomerPhone
    addinfo.MyBalance = float('%.2f' % 0)
    addinfo.AvailableBalance = float('%.2f' % 0)
    addinfo.MyIncome = float('%.2f' % 0)
    addinfo.Cidentity = 1
    db.session.add(addinfo)
    db.session.commit()

    return jsonify(resp)
Example #3
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)
    elif request.method == "POST":

        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 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)

        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 = getCurrentData()
            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 default_pwd != login_pwd:
            model_user.login_pwd = UserService.genePwd(login_pwd,
                                                       model_user.login_salt)
        model_user.updated_time = getCurrentData()

        db.session.add(model_user)
        db.session.commit()
        return jsonify(resp)
Example #4
0
def set():
    default_pwd = "******"
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = 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 ""
    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 ""

    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)
Example #5
0
def apply():

    default_pwd = "********"

    resp = {'code': 200, 'msg': '申请成功,将于三个工作日内进行审核~'}
    summnerNote = Apply()
    summnerNote.Cid = int(
        request.values['Cid']) if 'Cid' in request.values else -1
    summnerNote.ShopCategory = request.values[
        'ShopCategory'] if 'ShopCategory' in request.values else ''
    summnerNote.IdentityCard = request.values[
        'IdentityCard'] if 'IdentityCard' in request.values else ''
    summnerNote.IdentityCardHand = request.values[
        'IdentityCardHand'] if 'IdentityCardHand' in request.values else ''
    summnerNote.BusinessLicense = request.values[
        'BusinessLicense'] if 'BusinessLicense' in request.values else ''
    summnerNote.Contract = request.values[
        'Contract'] if 'Contract' in request.values else ''
    summnerNote.IDCard = request.values[
        'IDCard'] if 'IDCard' in request.values else ''
    summnerNote.ApplyProvince = request.values[
        'ApplyProvince'] if 'ApplyProvince' in request.values else ''
    summnerNote.ApplyCity = request.values[
        'ApplyCity'] if 'ApplyCity' in request.values else ''
    summnerNote.ApplyCounty = request.values[
        'ApplyCounty'] if 'ApplyCounty' in request.values else ''
    summnerNote.ApplyDetails = request.values[
        'ApplyDetails'] if 'ApplyDetails' in request.values else ''
    summnerNote.ApplyPhone = request.values[
        'ApplyPhone'] if 'ApplyPhone' in request.values else ''

    summnerNote.Applylogin_salt = UserService.geneSalt()
    ApplyPassword = request.values[
        'ApplyPassword'] if 'ApplyPassword' in request.values else ''
    if default_pwd != ApplyPassword:
        summnerNote.ApplyPassword = UserService.genePwd(
            ApplyPassword, summnerNote.Applylogin_salt)

    summnerNote.ApplyStatus = 0

    db.session.add(summnerNote)
    db.session.commit()

    return jsonify(resp)
Example #6
0
def add():
    req=request.values
    username=req['username'] if 'username' in req else ""
    password = req['password'] if 'password' in req else ""
    email = req['email'] if 'email' in req else ""
    salt=UserService.geneSalt()

    module_user=YiAdmin()
    module_user.username=username
    module_user.password=UserService.genePwd(password,salt)
    module_user.email=email
    module_user.level='1'
    module_user.state='2'
    module_user.admin='3'
    module_user.login_salt=salt
    module_user.lasttime=getCurrentData()
    try:
        db.session.add(module_user)
        db.session.commit()
    except Exception as e:
        return RespUtils.error('添加失败', e)

    return  RespUtils.success('添加成功')
Example #7
0
def getQuestion():
    resp = {'code':200, 'msg':'操作成功', 'data':{}}

    f = request.files['post-question'] if 'post-question' in request.files else ''
    app.logger.info(f)
    req = request.values

    app.logger.info(req)

    title = req['title'] if 'title' in req else ''
    content = req['content'] if 'content' in req else ''
    anony = req['anony'] if 'anony' in req else ''
    random_str = req['random_str'] if 'random_str' in req else ''
    token = req['token'] if 'token' in req else ''

    if title==None or len(title)<10 or content == None or len(content)<20:
        resp['code'] = -1
        resp['msg'] = "請確認內容符合字數規範,稍後重試"
        return jsonify(resp)

    if token==None or len(token)<1:
        resp['code'] = -1
        resp['msg'] = "無法獲取用戶信息,稍後重試"
        return jsonify(resp)

    if anony == 'true':
        anony = 0
    else:
        anony = 1

    uid = token.split("#")[1]

    if not uid:
        resp['code'] = -1
        resp['msg'] = 'error'
        return jsonify(resp)

    member_info = Member.query.filter_by(id=uid).first()

    if not member_info:
        resp['code'] = -1
        resp['msg'] = 'error'
        return jsonify(resp)

    hasIn = File.query.filter_by(salt=random_str).first()
    if hasIn:
        question = Question.query.filter_by(id=hasIn.qid).first()
        if not question:
            app.logger.error("no find")
        else:
            app.logger.error("find!!!!!!!!!!!!!!")
            app.logger.error("--------"+str(question.id))


    if not hasIn:
        question = Question()
        question.member_id = uid
        question.title = title
        question.content = content
        question.public = anony
        question.created_time = question.updated_time = getCurrentDate()

        db.session.add(question)
        db.session.commit()




    if f:
        # user_input = request.form.get("name")
        basepath = os.path.dirname(__file__)  # 当前文件所在路径
        basepath2 = os.path
        app.logger.info(basepath2)


        #src_imgname = str(question.id) + ".jpg"
        src_imgname = UserService.geneSalt(10) + ".jpg"
        upload_path = os.path.join('web/static/upload/')

        app.logger.info(basepath)

        if os.path.exists(upload_path) == False:
            os.makedirs(upload_path)
        f.save(upload_path + src_imgname)

        file_info = File()
        file_info.qid = question.id
        file_info.created_time = getCurrentDate()
        file_info.image = f.read()
        file_info.salt = random_str
        file_info.path = "static/upload/" + src_imgname

        db.session.add(file_info)
        db.session.commit()





    # im = cv2.imread(upload_path + src_imgname, 0)
    # save_path = os.path.join(basepath, 'static/resImg/')
    # if os.path.exists(save_path) == False:
    #     os.makedirs(save_path)
    # save_imgname = str(uuid.uuid1()) + ".jpg"
    # cv2.imwrite(save_path + save_imgname, im)
    # resSets["value"] = 10
    # resSets["resurl"] = "http://127.0.0.1:8090" + '/static/resImg/' + save_imgname

    return jsonify(resp)
Example #8
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()

        if user_info.nickname == app.config['SUPER_ADMIN']:
            return redirect(UrlManager.buildUrl('/account/index'))

        resp_data['user_info'] = user_info
        resp_data['current'] = 'user'
        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) < 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) < 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.login_salt = UserService.geneSalt()
        model_user.created_time = getCurrentDate()

    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)
Example #9
0
def set():
    default_pwd = "******"  #用于后面的判断是否对密码进行了修改
    # 要把current-user传进来,用于layout 中的个人设置页面
    current_user = session.current_user
    #如果方法是GET就直接展示页面,同时获取uid,用于识别要编辑的用户id,注意与current_user是两码事
    if request.method == "GET":
        req = request.args
        uid = int(req.get("id", 0))
        info = None
        if uid:
            info = User.query.filter_by(
                uid=uid).first()  #通过uid我们可以获取到该用户信息然后显示在页面上,用于修改
        return render_template("account/set.html",
                               current_user=current_user,
                               info=info)

    #如果方法是POST,那么获取数据,数据来自于set.js,这里省去了之前用过的form形式的收集数据的方法
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values  #参数较多是用values, 参数少时用args

    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)

    #查看是否已经重复,同时User.uid != id 是兼顾修改时用的。因为修改时是可能出现重复的,比如用户并没有修改登录名称
    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)
Example #10
0
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 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 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'] = "请输入符合规范的email"
        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)
    # 新增的时候判断是否存在相同用户,编辑的时候用户名本身已经存在,所以 不等于id的还有没有和它一样的
    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)
Example #11
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()
        current_user = g.current_user
        communities = Community.query.filter(
            Community.platform_id == current_user.platform_id)
        resp_data['info'] = info
        resp_data['communities'] = communities
        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
    platform_id = req['platform_id'] if 'platform_id' in req else ''
    platform_name = req['platform_name'] if 'platform_name' in req else ''
    community_id = req['community_id'] if 'community_id' in req else ''
    community_name = req['community_name'] if 'community_name' in req else ''
    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 ''
    benefit = req['benefit'] if 'benefit' in req else 0

    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 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) < 3:
        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)

    benefit = Decimal(benefit).quantize(Decimal('0.00'))
    if benefit < 0:
        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.platform_id = platform_id
        model_user.platform_name = platform_name
        model_user.community_id = community_id
        model_user.community_name = community_name
        model_user.email = email
        model_user.benefit = 0.00
        model_user.created_time = getCurrentDate()
        model_user.login_salt = UserService.geneSalt()

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.login_name = login_name
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.benefit = benefit

    model_user.updated_time = getCurrentDate()
    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
Example #12
0
def resetpwd():
    #设置默认密码,如果改变则说明修改过了
    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
        #传递到前端html文件
        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.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)
Example #13
0
def set():
    default_pwd = "******"  # 默认密码
    if request.method == "GET":
        resp_data = {}
        req = request.args  # 参数少时用args
        uid = int(req.get("id", 0))  # 获取当前id
        info = None
        if uid:  # 如果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': ''}
    req = request.values  # 参数多时用values ,参数少时用args
    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) < 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) < 5:
        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
        if login_pwd != default_pwd:  # 如果前端传来的密码不为6个*,则进行密码修改
            model_user.login_pwd = UserService.genePwd(
                login_pwd, model_user.login_salt)  # 需要导入UserService
    else:  # 新增
        model_user = User()
        model_user.created_time = getCurrentDate()
        model_user.login_salt = UserService.geneSalt()  # 生成加密密钥
        model_user.login_pwd = UserService.genePwd(
            login_pwd, model_user.login_salt)  # 需要导入UserService

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.email = email
    model_user.login_name = login_name
    model_user.updated_time = getCurrentDate()

    # 提交信息
    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
Example #14
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(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
        resp["msg"] = "编辑账号成功~~"
    else:
        # 新增
        model_user = User()
        model_user.login_salt = UserService.geneSalt()
        model_user.created_time = getCurrentDate()
        resp["msg"] = "新增账号成功~~"

    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)
Example #15
0
def set():
    default_pwd = '******'
    if request.method == 'GET':
        resq_data = {}
        res = request.args
        uid = res.get('id', 0)
        user_info = None
        if uid:
            user_info = User.query.filter_by(uid=uid).first()
        resq_data['user_info'] = user_info
        return ops_render('account/set.html', resq_data)

    resp = {'code': 200, 'msg': '用户创建成功', 'data': {}}
    res = request.values
    nickname = res['nickname'] if 'nickname' in res else False
    if nickname is None or nickname:
        resp['code'] = -1
        resp['msg'] = '用户名错误,重新输入'
        return jsonify(resp), 400
    id = res['id'] if 'id' in res else 0
    mobile = res['mobile'] if 'mobile' in res else False
    if mobile is None or mobile:
        resp['code'] = -1
        resp['msg'] = 'email错误,重新输入'
        return jsonify(resp), 400
    email = res['email'] if 'email' in res else False
    if email is None or email:
        resp['code'] = -1
        resp['msg'] = 'email错误,重新输入'
        return jsonify(resp), 400
    login_name = res['login_name'] if 'login_name' in res else False
    if login_name is None or login_name:
        resp['code'] = -1
        resp['msg'] = '登录名错误,重新输入'
        return jsonify(resp), 400
    login_pwd = res['login_pwd'] if 'login_pwd' in res else False
    if login_pwd is None or login_pwd:
        resp['code'] = -1
        resp['msg'] = '登录名错误,重新输入'
        return jsonify(resp), 400
    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), 400
    model_user = User.query.filter_by(uid=id).first()
    if model_user:
        user_info = model_user
    else:
        user_info = User()
        user_info.created_time = geneTime()
        login_salt = UserService.geneSalt()
        user_info.login_salt = login_salt
    user_info.nickname = nickname
    user_info.mobile = mobile
    user_info.email = email
    user_info.login_name = login_name
    if default_pwd != login_pwd:
        user_info.login_pwd = UserService.genePwd(login_pwd, user_info.login_salt)
    user_info.updated_time = geneTime()
    db.session.add(user_info)
    db.session.commit()
    return jsonify(resp)
Example #16
0
from application import app, db
from flask_mail import Mail, Message
from common.libs.Helper import ops_render, iPagination, getCurrentDate
from flask import Blueprint, render_template, request, redirect, jsonify, g, url_for, session
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, TimedJSONWebSignatureSerializer
from common.libs.user.UserService import UserService
from common.models.member.Member import Member

mail = Mail(app)
route_mail = Blueprint('mail_validation', __name__)

s = URLSafeTimedSerializer('Thisisasecret')
salt = UserService.geneSalt()
member_id = "0"


@route_mail.route('/validation', methods=["GET", "POST"])
def mail_validation():
    if request.method == "GET":
        resp_data = {}
        resp_data['current_user'] = ''

        g.email = None
        if request.method == "GET":
            if g.email:
                resp_data['email'] = g.email

    req = request.values
    email = req['email'] if 'email' in req else ''
    email = email + app.config['EMAIL_POSTFIX']
    token = req['key'] if 'key' in req else ''
Example #17
0
def set():
    default_pwd = "******"
    if request.method == "GET":
        # 判断 uid是否存在
        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 ''
    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 ) < 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 ) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录密码"
        return jsonify( resp )
    
    # 查询用户名是否 已经存在,而且 除去aclear本身!
    # 两种情况:1 修改 ;2 添加
    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.create_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
    model_user.updated_time = getCurrentDate()

    if login_pwd != default_pwd:
        model_user.login_pwd = UserService.genePwd( login_pwd, model_user.login_salt )      # 注意login_pwd不同
    

    db.session.add( model_user )
    db.session.commit()
    return jsonify( resp )    
Example #18
0
def set():
    default_pwd = '******'
    if request.method == 'GET':
        resp_data = {}
        req = request.args
        uid = req.get('id', '')
        uid = int(uid) if uid.isdigit() else 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 not nickname or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的用户名'
        return jsonify(resp)

    if not mobile or len(mobile) < 11:
        resp['code'] = -1
        resp['msg'] = '请输入正确的手机号'
        return jsonify(resp)

    if not email or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的邮箱'
        return jsonify(resp)

    if not login_name or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的登录用户名'
        return jsonify(resp)

    if not login_pwd or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的登录密码'
        return jsonify(resp)

    has_login_name = User.query.filter(User.login_name == login_name,
                                       User.uid != id).first()
    if has_login_name:
        resp['code'] = -1
        resp['msg'] = '登录用户名已存在,请重新输入'
        return jsonify(resp)

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

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

    db.session.add(user_model)
    db.session.commit()

    return jsonify(resp)
Example #19
0
def set():
    default_pwd = '******'
    if request.method == 'GET':
        resp_data = {}
        req = request.args
        uid = int(req.get('id', 0))
        info = None
        if uid and uid != 0:
            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) < 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:
        # 根据salt生成login_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)  # 成功添加
Example #20
0
def leaderApplicationApprove():
    resp = {'code': 200, 'msg': '审核操作成功~~', 'data': {}}
    print(request)
    req = request.values
    id = int(req['id']) if 'id' in req else 0
    member_id = int(req['member_id']) if 'member_id' in req else 0
    community_name = req['community_name'] if 'community_name' in req else ''
    province = req['province'] if 'province' in req else ''
    city = req['city'] if 'city' in req else ''
    description = req['description'] if 'description' in req else ''
    pickups = req['pickups'] if 'pickups' in req else ''
    name = req['name'] if 'name' in req else ''
    mobile = req['mobile'] if 'mobile' 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 ''
    email = req['email'] if 'email' in req else ''

    has_in = Community.query.filter(Community.name == community_name).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该社区名已存在,请换一个试试~~"
        return jsonify(resp)

    model_community = Community()
    model_community.platform_id = g.current_user.platform_id
    model_community.platform_name = g.current_user.platform_name
    model_community.name = community_name
    model_community.province = province
    model_community.city = city
    model_community.description = description
    model_community.pickups = pickups

    db.session.add(model_community)
    db.session.commit()

    community = Community.query.filter_by(
        platform_id=g.current_user.platform_id, name=community_name).first()

    model_user = User()
    model_user.platform_id = community.platform_id
    model_user.platform_name = community.platform_name
    model_user.community_id = community.id
    model_user.community_name = community.name
    model_user.email = email
    model_user.benefit = 0.00
    model_user.created_time = getCurrentDate()
    model_user.login_salt = UserService.geneSalt()
    model_user.nickname = name
    model_user.mobile = mobile
    model_user.login_name = login_name
    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()

    member = Member.query.filter_by(id=member_id).first()
    ApplicationService.changeCommunity(member.platform_id, member_id,
                                       community.id, community.name)

    application = Application.query.filter_by(id=id).first()
    application.status = 1
    db.session.add(application)
    db.session.commit()

    return jsonify(resp)
Example #21
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 = 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)
Example #22
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)  # 返回信息,更改成功
Example #23
0
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)
Example #24
0
def setPwd():
    default_pwd = "******"
    if request.method == 'GET':
        req = request.args
        uid = int(req.get('id'), 0)
        info = None
        if uid:
            info = User.query.filter_by(uid=uid).one_or_none()
        return ops_render("account/set.html", info=info)

    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    # 尽量不要使用id作为变量名, 内建函数 id()
    user_id = ParamsValidator.GetORSetValue(req, 'id', value=0)
    nickname = ParamsValidator.GetORSetValue(req, 'nickname', value="")
    mobile = ParamsValidator.GetORSetValue(req, 'mobile', value="")
    email = ParamsValidator.GetORSetValue(req, 'email', value="")
    login_name = ParamsValidator.GetORSetValue(req, 'login_name', value="")
    login_pwd = ParamsValidator.GetORSetValue(req, 'login_pwd', value="")

    if ParamsValidator.DataRequired(nickname):
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名"
    elif ParamsValidator.DataRequired(mobile):
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码"
    elif ParamsValidator.DataRequired(email):
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱"
    elif ParamsValidator.DataRequired(login_name):
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录用户名"
    elif ParamsValidator.DataRequired(login_pwd):
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录密码"
    elif User.query.filter(User.login_name == login_name, User.uid != user_id).one_or_none():
        resp['code'] = -1
        resp['msg'] = "该登录名已存在,请换一个试试"
    else:
        user_info = User.query.filter_by(uid=user_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:
            if user_info and user_info.uid == 1:
                resp['code'] = -1
                resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名"
                return jsonify(resp)
            # 当前密码 等于 默认密码的时候, 不更新密码  todo 只有输入密码不等于默认密码的时候才更新密码
            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)
Example #25
0
def set_page():
    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

        back_url = UrlManager.buildUrl('/account/index')

        if user_info.status != 1:  # 如果状态不是1,返回列表
            return redirect(back_url)

        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) < 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) < 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()  # 获取uid,判断是否存在,存在是更新,否则就新增
    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  # 变更登录名
    model_user.login_salt = UserService.geneSalt()

    if login_pwd != default_pwd:
        model_user.login_pwd = UserService.genePwd(
            login_pwd, model_user.login_salt)  # 判断用户是否修改密码,如果修改变更登录密码

    model_user.updated_time = getCurrentDate()

    # app.logger.info(user_info)
    db.session.add(model_user)  # 增加用户信息
    # app.logger.info(model_user)
    db.session.commit()  # 统一提交

    response = make_response(json.dumps(resp))
    # # 设置了cookie,那么就能设置统一拦截器,防止客户端没有cookie而能进入后台,同时定义cookie的加密方式geneAuthCode
    response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' %
                        (UserService.geneAuthCode(model_user), model_user.uid),
                        60 * 60 * 24 * 120)  # 生成cookie形式为 16进制加密字符#uid,保存120天
    return response
Example #26
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 )
    
    # 新建账户
    req = request.values
    resp = {'code':200,'msg':'操作成功','data':{}}

    id = req['id'] if 'id' in req else ''
    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) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入符合规范的登录密码~~'
        return jsonify(resp)
    # 如果新增用户,只需判断新增的用户名和数据库用户名是否相等即可
    # 如果是修改用户,需要判断除当前用户外还有没有相同的用户名
    # filter方法可以传入多个参数进行判断
    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.login_salt = UserService.geneSalt()
        model_user.created_time = getCurrentDate()

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

    db.session.add(model_user)
    db.session.commit()

    return jsonify(resp)
Example #27
0
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 None
    email = req['email'] if 'email' in req else None
    mobile = req['mobile'] if 'mobile' 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 nickname is None or len(nickname) < 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 mobile is None or len(mobile) < 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:
        if user_info and user_info.uid == 1:
            resp['code'] = -1
            resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名~~"
            return jsonify(resp)
        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)