Esempio n. 1
0
def register(request):
    """
    注册
    :param request:
    :return:
    """
    if request.session.get('is_login', False):
        redirect('/lianjia/')
    if request.method == 'POST':
        message = '请检查填写的内容!'

        # 通过表单验证提交的数据是否合规
        # registerForm = RegisterForm(request.POST)
        # if registerForm.is_valid():
        #     pass
        username = request.POST.get('username', '')
        nickname = request.POST.get('nickname', '')
        password = request.POST.get('password', '')
        mobile = password
        guid = 'u' + datetime.now().strftime('%Y%m%d%H%M%S') + str(
            random.randrange(1000, 9999))

        try:
            print('-' * 10)
            new_user = User()
            new_user.user_guid = guid
            new_user.user_name = username
            new_user.real_name = nickname
            new_user.mobile = mobile
            new_user.balance = 100
            new_user.all_balance = 80
            new_user.available_balance = 50
            new_user.create_date = datetime.now(pytz.utc)
            new_user.last_login_date = datetime.now(pytz.utc)
            new_user.gender = 1
            new_user.province = '河南'
            new_user.save()

            request.session['is_login'] = True
            request.session['user_guid'] = new_user.user_guid
            request.session['user_name'] = new_user.user_name
            return redirect('/lianjia/')

        except Exception as ex:
            message = '注册失败!'

        return render(request, 'lianjia/login.html', {
            'title': '注册',
            'year': datetime.now().year,
            'message': message,
        })

    return render(request, 'lianjia/register.html', {
        'title': '注册',
        'year': datetime.now().year,
    })
Esempio n. 2
0
 def register(cls, user_name, real_name, password, email, telephone,
              role_id, job):
     if UserManager.verify_existence(user_name):
         return jsonify({"code": 400, "message": "用户已存在,请更换用户名"})
     user = User()
     user.user_name = user_name
     user.real_name = real_name
     user.email = email
     user.telephone = telephone
     user.role_id = role_id
     user.job = job
     user.create_time = TimeManager.now()
     user.pwd = password
     db.session.add(user)
     user.save()
     return jsonify({"code": 200, "message": "注册成功"})