Пример #1
0
 def post(self, request):
     form = RegisterForm(request.POST)
     if form.is_valid():
         username = form.cleaned_data.get('username', '')
         email = form.cleaned_data.get('email', '')
         password = form.cleaned_data.get('password', '')
         users = User()
         users.username = username
         users.password = make_password(password)
         users.email = email
         users.is_active = False
         users.save()
         token = token_confirm.generate_validate_token(username)
         # message = "\n".join([u'{0},欢迎加入我的博客'.format(username), u'请访问该链接,完成用户验证,该链接1个小时内有效',
         #                      '/'.join([settings.DOMAIN, 'activate', token])])
         #send_mail(u'注册用户验证信息', message, settings.EMAIL_HOST_USER, [email], fail_silently=False)
         send_register_email.delay(email=email,
                                   username=username,
                                   token=token,
                                   send_type="register")
         return JsonResponse({
             'valid': True,
             'status': 200,
             'message': u"请登录到注册邮箱中验证用户,有效期为1个小时"
         })
     return JsonResponse({
         'status': 400,
         'data': form.errors,
         'valid': False
     })
Пример #2
0
def cliente_add(request):
    data = {}
    f = UserForm_cliente(request.POST)
    datos = request.POST
    if f.is_valid():
        with transaction.atomic():
            if verificar(f.data['cedula']):
                use = User()
                use.username = datos['cedula']
                use.cedula = datos['cedula']
                use.first_name = datos['first_name']
                use.last_name = datos['last_name']
                use.sexo = datos['sexo']
                use.email = datos['email']
                use.telefono = datos['telefono']
                use.celular = datos['celular']
                use.direccion = datos['direccion']
                use.tipo = 0
                use.password = make_password(datos['cedula'])
                use.save()
                permission = Permission.objects.get(codename='add_venta')
                permission2 = Permission.objects.get(codename='view_venta')
                use.user_permissions.add(permission)
                use.user_permissions.add(permission2)
                # venta.add_venta

                # u.user_permissions.add(permission)
                data['resp'] = 'error'
            else:
                f.add_error("cedula",
                            "Numero de Cedula no valido para Ecuador")
                data['error'] = f.errors
    else:
        data['error'] = f.errors
    return HttpResponse(json.dumps(data), content_type="application/json")
Пример #3
0
def register(request):
    r = json.loads(request.body)
    account = r['account']
    password = r['password']
    code = r['code']
    if judge_type(account) is None:
        return JsonResponse({'success': False, 'msg': "账号格式有误!"})
    # 从redis缓存中读取缓存信息 account唯一
    check_code = cache.get(account)
    print(check_code)
    # 验证验证码是否正确
    if check_code == code:
        # 新加用户
        user = User()
        user.username = '******' + shuffle_str(True)[0:6]
        # 判断账号类型
        if judge_type(account) == 'phone':
            user.phone = account
        else:
            user.email = account
        # 密码加密
        user.password = encrypt(password)
        print(user.password)
        # 保存
        user.save()
        return JsonResponse({'success': True, 'msg': "注册成功!"})
    else:
        return JsonResponse({'success': False, 'msg': "验证码错误!"})
Пример #4
0
 def save_data(self, f, datos):
     data = {}
     if f.is_valid():
         use = User()
         use.username = datos['cedula']
         use.cedula = datos['cedula']
         use.first_name = datos['first_name']
         use.last_name = datos['last_name']
         use.sexo = datos['sexo']
         use.email = datos['email']
         use.telefono = datos['telefono']
         use.celular = datos['celular']
         use.direccion = datos['direccion']
         use.tipo = 0
         use.password = make_password(datos['cedula'])
         use.save()
         data['resp'] = True
         data['cliente'] = use.toJSON()
         grupo = Group.objects.get(name__icontains='cliente')
         usersave = User.objects.get(id=use.id)
         usersave.groups.add(grupo)
         usersave.save()
     else:
         data['error'] = f.errors
     return data
Пример #5
0
def bindingQQ(request):
    """
    QQ 注册账号
    :param request:
    :return:
    """
    if request.method == 'POST':
        openid = request.POST.get('openid')
        figureurl_qq_1 = request.POST.get('figureurl_qq_1')
        nickname = request.POST.get('nickname')
        password = request.POST.get('password')
        password1 = request.POST.get('password1')
        email = request.POST.get('email')
        if password != password1:
            return render(
                request, 'pc/qqregister.html', {
                    'openid': openid,
                    'figureurl_qq_1': figureurl_qq_1,
                    'nickname': nickname,
                    'error': '两次密码不一致'
                })
        else:
            User.objects.filter(email=email).exists()
            if User.objects.filter(email=email).exists():
                return render(
                    request, 'pc/qqregister.html', {
                        'openid': openid,
                        'figureurl_qq_1': figureurl_qq_1,
                        'nickname': nickname,
                        'error': '邮箱已存在'
                    })
            else:
                user = User()
                user.username = nickname
                user.email = email
                user.user_image = figureurl_qq_1
                user.is_staff = False
                user.is_superuser = False
                user.is_active = True
                user.password = make_password(password1)
                user.save()
                qq = OAuthQQ()
                user_id = get_object_or_404(User, email=email).id
                qq.user_id = user_id
                msg = UserMessage()
                msg.user_id = user_id
                msg.to_user = User.objects.get(is_superuser=True)
                msg.message = '欢迎加入本站,在使用过程中有什么疑问,请联系管理员,Email: <a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=iuzv5O3g4_T748rs7_Tt4OPk__Ok6eXn" style="text-decoration:none;">[email protected]</a>'
                msg.has_read = False
                msg.is_supper = True
                msg.save()
                qq.qq_openid = openid
                qq.nickname = nickname
                qq.figureurl_qq = figureurl_qq_1
                qq.save()
                user = authenticate(request, username=email, password=password)
                login(request, user)
                return HttpResponseRedirect(reverse('home'))
Пример #6
0
def bindingQQ(request):
    """
    QQ 注册账号
    :param request:
    :return:
    """
    if request.method == 'POST':
        openid = request.POST.get('openid')
        figureurl_qq_1 = request.POST.get('figureurl_qq_1')
        nickname = request.POST.get('nickname')
        password = request.POST.get('password')
        password1 = request.POST.get('password1')
        email = request.POST.get('email')
        if password != password1:
            return render(
                request, 'pc/qqregister.html', {
                    'openid': openid,
                    'figureurl_qq_1': figureurl_qq_1,
                    'nickname': nickname,
                    'error': '两次密码不一致'
                })
        else:
            User.objects.filter(email=email).exists()
            if User.objects.filter(email=email).exists():
                return render(
                    request, 'pc/qqregister.html', {
                        'openid': openid,
                        'figureurl_qq_1': figureurl_qq_1,
                        'nickname': nickname,
                        'error': '邮箱已存在'
                    })
            else:
                user = User()
                user.username = nickname
                user.email = email
                user.user_image = figureurl_qq_1
                user.password = make_password(password1)
                user.save()
                qq = OAuthQQ()
                user_id = get_object_or_404(User, email=email).id
                qq.user_id = user_id
                msg = UserMessage()
                msg.user_id = user_id
                msg.to_user = User.objects.get(username='******')
                msg.message = '欢迎加入本站,在使用过程中有什么疑问,请联系管理员'
                msg.has_read = False
                msg.is_supper = True
                msg.save()
                qq.qq_openid = openid
                qq.nickname = nickname
                qq.figureurl_qq = figureurl_qq_1
                qq.save()
                user = authenticate(request, username=email, password=password)
                login(request, user)
                return HttpResponseRedirect(reverse('home'))
Пример #7
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 注册用户
            user = User()
            user.username = username
            user.password = hashlib.sha256(
                password.encode('utf-8')).hexdigest()
            user.phone = phone
            # 添加并提交
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.user_center'))
    return render_template('user/register.html')
Пример #8
0
def register():
    """用户注册"""
    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        confirm_password = request.form.get('confirmpwd')
        email = request.form.get('email')
        phone = request.form.get('phone')
        if password == confirm_password:
            user = User()
            user.username = username
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.login'))
    return render_template('user/register.html')
Пример #9
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            user = User()
            user.username = username
            # 使用自带的函数实现加密:generate_password_hash
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
    return render_template('user/register.html')
Пример #10
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            user = User()
            user.username = username
            user.password = hashlib.md5(password.encode('utf-8')).hexdigest()
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
        else:
            return '二次密码不一致,请重新输入'
    return render_template('user/register.html')
Пример #11
0
    def test_password_hashing(self):
        user = User(
            email='*****@*****.**',
            password='******',
        )
        user.save()

        # Check that password is converted to a hash upon saving
        self.assertTrue(check('password', user.password))

        # Check that password is not hashed again when its value did not change
        user.save()
        self.assertTrue(check('password', user.password))

        # Check that password is hashed again when its value changed
        user.password = '******'
        user.save()
        self.assertFalse(check('password', user.password))
        self.assertTrue(check('$this_is_my_new_password', user.password))
Пример #12
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if password == repassword:
            # 注册用户
            user = User()
            user.username = username
            # 使用自带的函数实现加密:generate_password_hash
            user.password = generate_password_hash(password)
            print(password)
            user.phone = phone
            user.email = email
            # 添加并提交
            db.session.add(user)
            db.session.commit()
            return '注册成功!'
    return render_template('user/register.html')
Пример #13
0
 def post(self, request):
     username = request.POST.get("user_name")
     password = request.POST.get("pwd")
     email = request.POST.get('email')
     allow = request.POST.get('allow')
     if not all([username, password, email]):
         return render(request, 'register.html', {'errmsg': '信息填写不完整'})
     if allow != 'on':
         return render(request, 'register.html', {'errmsg': '请同意协议'})
     try:
         user = User.objects.get(username=username)
     except Exception as e:
         print(e)
         user = None
     if user is not None:
         return render(request, 'register.html', {'errmsg': '用户已存在'})
     user = User()
     user.username = username
     user.password = password
     user.email = email
     user.save()
     return redirect(reverse('user:login'))
Пример #14
0
def register():
    user, types = user_type()
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        email = request.form.get('email')
        if repassword == password:
            user = User()
            user.username = username
            user.password = generate_password_hash(password)
            user.phone = phone
            user.email = email
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.index'))
        else:
            return render_template('user/register.html',
                                   msg='两次密码不一致',
                                   types=types)
    return render_template('user/register.html', types=types)
Пример #15
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')  # request是从页面获取的,表单一点提交就会提交信息
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:  # 如果密码一致
            # 1注册用户,与模型结合
            user = User()
            # 2给对象的属性赋值
            user.username = username  # .username表示访问user的属性,获取属性
            user.password = generate_password_hash(
                password)  # 使用自带的函数实现加密generate_password_hash
            user.phone = phone  # 属性赋值
            # 添加并提交
            # 3.将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4.提交到数据库
            db.session.commit()
            return render_template('base.html')

    return render_template('user/register.html')
Пример #16
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            #与模型结合,拿取属性的值
            #1.找到模型类并创建对象
            user = User()
            #2.给对象的属性赋值
            user.username = username
            user.password = hashlib.md5(password.encode('utf-8')).hexdigest()
            user.phone = phone
            #添加数据至数据库
            #3.将user对象添加到session()中【缓存】
            db.session.add(user)
            #4.将缓存的数据插入到数据库里,提交数据
            db.session.commit()
            return redirect(url_for('user.user_center'))
        else:
            return "二次密码不一致"
    return render_template('user/register.html')
Пример #17
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 与模型结合,完成数据库的添加
            # 1. 找到模型类,并创建对象
            user = User()
            # 2. 给对象的属性赋值
            user.username = username
            user.password = password
            user.phone = phone
            # 添加进数据库
            # 3. 将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4. 提交到数据库
            db.session.commit()
            return '用户注册成功!'
        else:
            return '两次密码不一致!'
    return render_template('user/register.html')
Пример #18
0
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        repassword = request.form.get('repassword')
        phone = request.form.get('phone')
        if password == repassword:
            # 与模型结合
            # 1.找到模型类并创建对象
            user = User()
            # 2. 给对象赋值
            user.username = username
            user.password = password
            user.phone = phone
            # 添加到数据库
            # 3.将user对象添加到session中(类似缓存)
            db.session.add(user)
            # 4.提交数据部分
            db.session.commit()
            return '用户添加成功'
        else:
            return '两次密码不一致'
    return render_template('user/register.html')
Пример #19
0
def register():
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']

        # users.append(
        #     {'username': username, 'password': password}
        # )

        # 1使用模型类并创建对象
        user = User()
        # 2 给对象赋值
        user.username = username
        user.password = password
        # 3添加数据
        db.session.add(user)
        # 4 提交
        db.session.commit()

        return "注册成功"

        # return redirect(url_for('user.index'))

    return render_template('user/register.html')