Exemplo n.º 1
0
def login_pwd():
    api_logger.debug('user phone_login get action!')
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('u_phone')
        u_auth_string = resp.get('u_auth_string')
        if all((bool(u_phone), bool(u_auth_string))):
            udao = UserDao()
            # 验证手机号在数据库中是否存在
            if udao.check_login_phone(u_phone):
                try:
                    # 验证密码是否正确
                    login_user = udao.login_pwd(u_phone, u_auth_string)[0]
                    if login_user.get('id'):
                        token = cache.new_token()
                        cache.save_token(token, login_user.get('id'))
                        udao.user_update('is_active', 1, 'u_phone', u_phone)
                        return jsonify({'code': 200,
                                        'token': token,
                                        'user_data': login_user
                                        })
                    return jsonify(login_user)
                except Exception as e:
                    return jsonify({'code': 202,
                                    'msg': str(e)
                                    })
            return jsonify({'code': 304,
                            'msg': '该手机尚未注册'
                            })
        else:
            return jsonify({
                'code': 101,
                'msg': '请求参数u_phone和u_auth_string必须存在'
            })
    return jsonify({'code': 304, 'msg': '传入数据为空'})
Exemplo n.º 2
0
def forgot_pwd():
    api_logger.debug('user forget get action!')
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('phone')
        msg_code = resp.get('msg')
        u_auth_string = resp.get('auth_string')
        if all((bool(u_phone), bool(msg_code), bool(u_auth_string))):
            udao = UserDao()
            # 验证手机号在数据库中是否存在
            if udao.check_login_phone(u_phone):
                login_user = udao.login_msg(u_phone, msg_code)   # 检查验证码
                if login_user.get('id'):
                    token = cache.new_token()
                    cache.save_token(token, id)
                    udao.user_update('u_auth_string', u_auth_string, 'u_phone', u_phone)  # 更新密码
                    udao.user_update('is_active', 1, 'u_phone', u_phone)  # 更新状态
                    # PhoneDao().save(**{'phone': u_phone, 'code': msg_code, 'send_type': '登录', })
                    return jsonify({'code': 200, 'token': token, 'user_data': login_user})
                return jsonify(login_user)
            else:   # 手机号码不存在,提示
                return jsonify({'code': 300, 'msg': '请填写注册手机号'})
        else:
            return jsonify({
                'code': 101,
                'msg': '请求参数u_phone,msg_code,u_auth_string必须存在'
            })
    return jsonify({'code': 304, 'msg': '传入数据为空'})
Exemplo n.º 3
0
def change():
    api_logger.debug('user forget get action!')
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('phone')
        nickname = resp.get('nickname')
        auth_string = resp.get('auth_string')
        u_auth_string = make_password(auth_string)
        if all((bool(u_phone), bool(nickname), bool(u_auth_string))):
            udao = UserDao()
            details = udao.get_profile(u_phone)
            if details.get('id'):
                token = cache.new_token()
                cache.save_token(token, id)
                udao.user_update('nickname', nickname, 'u_auth_string', u_auth_string)  # 更新密码
                udao.user_update('is_active', 1, 'u_phone', u_phone)  # 更新状态
                # PhoneDao().save(**{'phone': u_phone, 'code': msg_code, 'send_type': '登录', })
                return jsonify({'code': 200,
                                'token': token,
                                'user_data': details})
            else:
                return details
        return jsonify({
            'code': 300,
            'msg': '数据不能为空'
        })
    return jsonify({'code': 304,
                    'msg': '传入数据为空'
                    })
Exemplo n.º 4
0
def code_login():
    r_data = request.get_json()
    if r_data:
        phone = r_data['phone']
        pwd = r_data['pwd']
        #判断接受的数据是否为空
        if all((phone, pwd)):
            u_password = UserDao().get_pwd('u_tel',phone)
            if check_password(pwd,u_password):
                user_id = UserDao().get_id('u_tel',phone)
                print(user_id)
                if user_id is not None:
                    token = uuid.uuid4().hex
                    save_token(token, user_id)
                    data = UserDao().get_profile(user_id)
                    return jsonify({
                        'code': 200,
                        'msg': '登录成功,欢迎使用MT外卖品台',
                        'token': token,
                        'data': data
                    })
    return jsonify({
        "code": 207,
        "msg": "手机号或者密码错误,请重新输入"
    })
Exemplo n.º 5
0
def login_msg():
    api_logger.debug('user phone_login get action!')
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('u_phone')
        msg_code = resp.get('msg_code')
        if all((bool(u_phone), bool(msg_code))):
            udao = UserDao()
            login_user = udao.login_msg(u_phone, msg_code)
            # 检查验证码并检查手机号,如果存在,且验证码正确,则登录,否则注册
            if login_user.get('id'):   # 验证码正确
                token = cache.new_token()
                cache.save_token(token, login_user.get('id'))
                udao.user_update('is_active', 1, 'u_phone', u_phone)
                # PhoneDao().save(**{'phone': u_phone, 'code': msg_code, 'send_type': '登录'})
                return jsonify({'code': 200,
                                'token': token,
                                'user_data': login_user
                                })
            return jsonify(login_user)
        else:
            return jsonify({
                'code': 101,
                'msg': '请求参数u_phone和msg_code必须存在'
            })
    return jsonify({'code': 304, 'msg': '传入数据为空'})
Exemplo n.º 6
0
def login_str():
    try:
        phone = request.form.get('phone')
        auth_str = request.form.get('auth_str')

        dao = UserDao()
        if dao.check_login_name(phone):  # 检测用户名是否存在
            if dao.login_str(phone, auth_str):  # 检测密码是否正确
                token = cache.new_token()
                user_id = dao.find_userid(phone)
                save_token(token, user_id)
                return jsonify({
                    'code': 200,
                    'msg': 'ok',
                    'token': token,
                })
        return jsonify({
            'code': 406,
            'msg': '用户名或密码输入错误',
        })
    except:
        return jsonify({
            "code": 400,
            "msg": "注册登录失败"
        })
Exemplo n.º 7
0
def user_login():
    api_logger.debug('user login get action!')
    # 验证参数
    userTel = request.args.get('userTel', None)
    password = request.args.get('password', None)
    if all((bool(userTel), bool(password))):
        dao = UserDao()
        # 获取登录用户的信息
        try:
            login_user = dao.login(userTel, password)
            # 生成token
            token = cache.new_token()
            #用户基本信息
            sql = 'select * from wklc_users ' \
                  'where userTel=%s'
            user_datas = dao.query(sql, userTel)[0]
            # 将token存在redis的缓存中,绑定的数据可以是用户Id也可以是用户的信息
            cache.save_token(token, user_datas['id'])
            user_id = user_datas['id']
            sql = 'select lendTime from wklc_lendrecords ' \
                  'where user_id=%s and product_id=9022'
            product = dao.query(sql, user_id)
            if product:
                if product[0]['lendTime'].toordinal() + 7 < datetime.now(
                ).toordinal():
                    user_datas['xyMoney'] = 0
            money = 0
            for i in login_user[:-2]:
                money += i["num"]
            totalMoney = float('%.2f' % (user_datas['zyMoney'] + money))
            yersterdayReturn = login_user[5]['num']
            totalReturn = login_user[6]['num']
            dao.update_user(totalMoney, yersterdayReturn, totalReturn, user_id)
            return jsonify({
                'code': 200,
                'token': token,
                'userTel': user_datas['userTel'],
                'userGrade_id': user_datas['userGrade_id'],
                'totalMoney': totalMoney,
                'zyMoney': user_datas['zyMoney'],
                'xyMoney': user_datas['xyMoney'],
                'yersterdayReturn': yersterdayReturn,
                'totalReturn': totalReturn,
                'userKfCoin': user_datas['userKfCoin'],
                'userfuZuan': user_datas['userfuZuan'],
                'Account': login_user[:-2]
            })
        except Exception as e:
            return jsonify({'code': 202, 'msg': str(e)})
    else:
        return jsonify({'code': 101, 'msg': '请求参数login_name和auth_str必须存在'})
Exemplo n.º 8
0
def user_regist():
    r_data = request.get_json()
    print(r_data,request.headers.get('Content-Type'))
    if r_data:
        phone = r_data['phone']
        code = r_data['code']
        #判断接受的数据是否为空
        if all((phone,code)):
            res = check_sms(phone,code)
            print(res)
            if not res:

                if UserDao().check_phone(phone):
                    c_data = {
                        'u_username' : "KMP" + phone,
                        'u_tel' : phone,
                        'u_headpic' : '',
                        'u_nickname' : "Nk" + phone,
                        'u_email':phone+"@tel.com",
                        'is_vip':False,
                        'is_active':True,
                    }
                    print(c_data)
                    UserDao().save(**c_data)
                else:
                    if UserDao().set_userinfo(key='is_active',value=True,where='u_tel',args=phone):
                        pass
                    else:
                        return jsonify({'code':207,'msg':'服务器出现异常,请稍后再试!!!'})

                user_id = UserDao().get_id('u_tel',phone)
                print(user_id)
                data = UserDao().get_profile(user_id)
                token = uuid.uuid4().hex
                save_token(token, user_id)
                api_logger.info("登录成功")
                return jsonify({
                    'code':200,
                    'msg':'登录成功,欢迎使用MT外卖品台',
                    'token':token,
                    'data':data
                })
    api_logger.error("手机号或验证码错误")
    return jsonify({
                "code": 207,
                "msg": "手机号或者验证码错误!!!"
            })
Exemplo n.º 9
0
def login_code():
    try:
        # 前端请求的Content-Type: application/json
        phone = request.form.get('phone')
        input_code = request.form.get('input_code')
        # 验证上传的必须的数据是否存在
        if not confirm(phone, input_code):  # 验证验证码是否一致
            return jsonify({
                "code": 400,
                "msg": "验证码输入错误,请重新输入",
            })
        req_data = {"phone": phone}  # 验证通过之后将验证码从req_data中删除
        dao = UserDao()
        if not dao.check_login_name(phone):  # 检测用户名是否存在
            req_data['phone'] = phone
            req_data['nick_name'] = ''.join(random.sample('zyxwvutsrqponmlkjihgfedcba', 14))
            req_data['create_time'] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
            req_data['photo'] = '7b6b118c30e345ca8f1f6e6584b2e7fe'
            req_data['login_auth_str'] = '677698c118bf5e6974f19fd2eb2a5b67'
            req_data['update_time'] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
            req_data["balance"] = '50000'
            req_data["pay_pwd"] = "fb95decf3125dc6057a09188b238ff18"
            req_data['activated'] = '1'
            dao.save(**req_data)  # 不存在则存入数据库中,在读取数据

        user_id = dao.find_userid(phone)
        token = cache.new_token()  # 设置新token
        save_token(token, user_id)
        return jsonify({
            'code': 200,
            'msg': 'ok',
            'token': token,
        })
    except:
        return jsonify({
            "code":400,
            "msg":"注册登录失败"
        })
Exemplo n.º 10
0
def user_login():
    api_logger.debug('user login get action!')
    # 验证参数
    login_name = request.args.get('login_name', None)
    auth_str = request.args.get('auth_str', None)
    if all((bool(login_name), bool(auth_str))):
        dao = UserDao()
        # 获取登录用户的信息
        try:
            login_user = dao.login(login_name, auth_str)
            # 生成token
            token = cache.new_token()

            # 将token存在redis的缓存中,绑定的数据可以是用户Id也可以是用户的信息
            cache.save_token(token, login_user.get('user_id'))
            return jsonify({
                'code': 200,
                'token': token,
                'user_data': login_user
            })
        except Exception as e:
            return jsonify({'code': 202, 'msg': e})
    else:
        return jsonify({'code': 101, 'msg': '请求参数login_name和auth_str必须存在'})
Exemplo n.º 11
0
def checking_code():
    try:
        phone = request.form.get('phone')
        input_code = request.form.get('input_code')
        # 验证上传的必须的数据是否存在
        if not confirm(phone, input_code):  # 验证验证码是否一致
            return jsonify({
                "code": 400,
                "msg": "验证码输入错误,请重新输入",
            })
        token = cache.new_token()  # 设置新token
        dao = UserDao()
        user_id = dao.find_userid(phone)
        save_token(token, user_id)
        return jsonify({
            'code': 200,
            'msg': 'ok',
            'token': token,
        })
    except:
        return jsonify({
            "code":400,
            "msg":"验证失败"
        })
Exemplo n.º 12
0
def user_regist():
    # 前端请求的Content-Type: application/json
    req_data = None
    api_logger.info(request.headers)
    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()

    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({'code': 9000, 'msg': '请上传json数据,且参数必须按api接口标准给定'})
    api_logger.debug(req_data)
    # 验证上传的必须的数据是否存在
    if all((req_data.get('userTel', False), req_data.get('password', False),
            req_data.get('code', False))):
        input_code = req_data.get('code')
        phone = req_data.get('userTel')
        password = req_data.get('password')
        if dao.check_login_name(phone):
            if confirm(phone, input_code):
                req_data['password'] = make_password(req_data.get('password'))
                req_data['userName'] = req_data[
                    'userTel'][:3] + "******" + req_data['userTel'][-3:]
                req_data['userGrade_id'] = '1',
                req_data['totalMoney'] = '0'
                req_data['yersterdayReturn'] = '0'
                req_data['totalReturn'] = '0'
                req_data['userKfCoin'] = '500000'
                req_data['userfuZuan'] = '0'
                req_data['xyMoney'] = '5000'
                req_data['zyMoney'] = '0'
                req_data['is_Verify'] = '0'
                req_data['userPic'] = '0'
                req_data.pop('code')
                if dao.save(**req_data):

                    sql = 'select * from wklc_users ' \
                          'where userTel=%s'
                    userTel = req_data['userTel']
                    user_datas = dao.query(sql, userTel)[0]
                    req_data2 = {}
                    req_data2['user_id'] = user_datas['id']
                    req_data2['monthAccount'] = 0
                    req_data2["sensonAccount"] = 0
                    req_data2["yearAccount"] = 0
                    req_data2['specialAccount'] = 0
                    req_data2['virtualPrincipal'] = 0
                    dao.save2(**req_data2)

                    login_user = dao.login(userTel, password)

                    token = cache.new_token()
                    # 用户基本信息
                    sql = 'select * from wklc_users ' \
                          'where userTel=%s'

                    # 将token存在redis的缓存中,绑定的数据可以是用户Id也可以是用户的信息
                    cache.save_token(token, user_datas['id'])
                    #注册成功添加出借50000出借7天
                    data = {}
                    data['user_id'] = user_datas['id']
                    data['product_id'] = 9022
                    data['lendUserTel'] = req_data['userName']
                    data['lendTime'] = datetime.now()
                    data['lendMoney'] = 5000
                    dao.lend_save2(**data)
                    money = 0
                    for i in login_user[:-2]:
                        money += i["num"]
                    totalMoney = float('%.2f' %
                                       (user_datas['zyMoney'] + money))
                    yersterdayReturn = login_user[5]['num']
                    totalReturn = login_user[6]['num']
                    dao.update_user(totalMoney, yersterdayReturn, totalReturn,
                                    user_datas['id'])
                    return jsonify({
                        'code': 200,
                        'token': token,
                        'userTel': user_datas['userTel'],
                        'userGrade_id': user_datas['userGrade_id'],
                        'totalMoney': totalMoney,
                        'zyMoney': user_datas['zyMoney'],
                        'xyMoney': user_datas['xyMoney'],
                        'yersterdayReturn': yersterdayReturn,
                        'totalReturn': totalReturn,
                        'userKfCoin': user_datas['userKfCoin'],
                        'userfuZuan': user_datas['userfuZuan'],
                        'Account': login_user[:-2]
                    })

                else:
                    return jsonify({
                        'code': 300,
                        'msg': '插入数据失败, 可能存在某一些字段没有给定值'
                    })
            else:
                return jsonify({'code': 203, 'msg': '验证码输入错误'})
        else:
            return jsonify({'code': 201, 'msg': '用户名已存在,不能再注册'})

    else:
        return jsonify({'code': 204, 'msg': '输入参数不全,参数必须按api接口标准给定'})