Ejemplo n.º 1
0
Archivo: user.py Proyecto: Paddyy/flask
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        #根据数据生成对象
        u = User(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
        )
        print('*' * 50)
        print(u.username)
        #保存对象
        db.session.add(u)
        # 必须提交
        db.session.commit()

        token = u.generate_activate_token()
        send_mail('Paddy论坛账户激活',
                  form.email.data,
                  'user/activate',
                  username=form.username.data,
                  token=token)
        flash('邮件已发送,请点击链接完成用户激活')
        #跳转页面
        return redirect(url_for('main.index'))
    return render_template('user/register.html', form=form)
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        form = RegisterForm(request.POST)

        # 验证码验证

        yzm1 = request.POST.get('message')
        yzm2 = request.session.get('code')
        # 判定验证码是否匹配
        print(yzm1, yzm2)
        res = (yzm1 == yzm2)
        # 如果验证码不匹配
        if not res:
            form.errors['yzm'] = "验证码不匹配,请重新验证"
        print(form, form.is_valid())
        if res and form.is_valid():
            print('==========')  # 验证通过
            request.session.clear()

            username = form.cleaned_data.get('mobile')

            password = form.cleaned_data.get('password')

            birthday = form.cleaned_data.get('birthday')
            print(000000000000000000000000)
            User.objects.create_user(username=username,
                                     email=None,
                                     password=password)
            user = User.objects.get(username=username)
            user.birthday = birthday
            user.save()
            login(request, user)
            return redirect(reverse('app:index'))

        return render(request, 'register.html')
Ejemplo n.º 3
0
Archivo: views.py Proyecto: Gcxy1/666
def register(request):
    if request.method == 'POST':
        print(222222222)
        #使用forms
         # 获取Form数据
        forms= RegisterForm(request.POST)
        #使用forms.is_valid()方法,对forms进行判断
        if forms.is_valid():  #判断forms的输入是否正确?
            #正确就获取数据,进行注册
            phone = forms.cleaned_data.get('phone')
            password = forms.cleaned_data.get('password')
            email = forms.cleaned_data.get('email')
            print("*"*30)
            print(phone)
            print(password)
            print(email)
            #注册cretae:添加
            User.objects.create(phone=phone,email=email,password=my_md5(password))

            return redirect(reverse('login'))
        else:
            #注册失败,返回form.errors
            return render(request,'register.html',{'errors':forms.errors})
    print(11111111)
    return render(request,'register.html')
Ejemplo n.º 4
0
def register_user():
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            print(form)
            return redirect('/')
    return render_template("register1.htm",**locals())
Ejemplo n.º 5
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():

            if User.objects.filter(email=form.cleaned_data['email']).exists():
                messages.warning(
                    request,
                    f"{form.cleaned_data['email']} is already in exists")
                return redirect(reverse('register'))

            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            gender = form.cleaned_data['gender']
            date_of_birth = form.cleaned_data['date_of_birth']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']

            user = User.objects.create(first_name=first_name,
                                       last_name=last_name,
                                       gender=gender,
                                       date_of_birth=date_of_birth,
                                       age=calculateAge(date_of_birth),
                                       email=email,
                                       password=generateHash(password))
            if user:
                messages.success(request, 'Signup successful')
                return redirect(reverse('login_user'))
            else:
                messages.error(request, "Ohh Shit, something went wrong")
    else:
        form = RegisterForm()

    return render(request, 'Register.html', {'form': form})
Ejemplo n.º 6
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            data.pop('confirm')
            print(data)
            res = User.objects.create_user(**data)

        else:
            return render(request, 'page-register.html', locals())
    return render(request, 'page-register.html')
Ejemplo n.º 7
0
def register_user():
    form = RegisterForm(request.form)
    if request.method == 'POST':
        # 验证成功,返回True,否则返回False
        if form.validate_on_submit():
            # 获取验证数据
            username = form.username.data
            password = form.password.data
            user = User(username=username)
            # 保存用户信息
            user.password = hashlib.sha1(password.encode('utf8')).hexdigest()
            db.session.add(user)
            db.session.commit()
            return redirect("/")
    return render_template("register.html", **locals())
Ejemplo n.º 8
0
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            # 获取验证数据
            username = form.nickname.data.upper()
            password = form.password.data
            user = User(username=username)
            # 保存用户信息
            user.password = hashlib.sha256(password.encode()).hexdigest()
            db.session.add(user)
            db.session.commit()
            user = User.query.filter(User.username == username).first()
            session['uid'] = user.uid
            return redirect(url_for('user.blog'))
    return render_template('register.htm', **locals())
Ejemplo n.º 9
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data.pop('confirm')
            u = User.objects.filter(username=data['username'])
            if u:
                return render(request, 'register.html', {'msg': '用户名已存在'})

            user = User.objects.create_user(**data)
            if user:
                return render(request, '飞机2.html')
        else:
            return render(request, 'register.html', {'form': form})

    return render(request, 'register.html')
Ejemplo n.º 10
0
def user_register(request):
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data.pop("confirm")
            # 把用户写入数据库
            # 密码会做签名,不能手动签名加密password
            user = User.objects.create_user(**data)
            if user:
                print(user.uid)
                return redirect('/tupian_pc_index/')
            else:
                return render(request, "register.html", {'form': form})
        else:
            return render(request, "register.html", {'form': form})
        # get请求
    return render(request, "register.html")
Ejemplo n.º 11
0
def zhuce(request):
    if request.method == 'POST':

        form = RegisterForm(request.POST)
        #验证表单
        if form.is_valid():

            data = form.cleaned_data
            data.pop('confirm')
            u = User.objects.filter(username=data['username'])
            if u:

                return render(request, '注册.htm', {'msg': '用户名已存在'})
            user = User.objects.create_user(**data)
            if user:

                return redirect('App:loginb')

    return render(request, '注册.htm', locals())
Ejemplo n.º 12
0
Archivo: views.py Proyecto: Yichr/Yichr
def chp(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        try:
            if form.is_valid():
                # data = form.cleaned_data
                username = form.changed_data.get('username')
                user = User.objects.get(username=username)
                if user:
                    password = form.cleaned_data.get('password')
                    user.password = password
                    user.save()
            else:
                return render(request, 'change_psw.html', {'form': form})
        except:
            flash = '无此用户'
            return render(request, 'change_psw.html', locals())
            # return render(request, 'change_psw.html', {'form': form})

    return render(request, 'change_psw.html')
Ejemplo n.º 13
0
def register(request):
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            # uid = randint(100,999)
            data = form.cleaned_data
            data.pop("confirm")
            data['uid'] = randint(100, 999)
            # 把用户写入数据库
            # 密码会做签名,不能手动签名加密password
            user = User.objects.create_user(**data)
            if user:
                print(user.uid)
                return redirect('/logind/')
            else:
                return render(request, "register.html", {'form': form})
        else:
            return render(request, "register.html", {'form': form})
        # get请求
    return render(request, "register.html")
Ejemplo n.º 14
0
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            # 获取数据
            phone = form.phone.data
            username = form.username.data
            password = form.password.data
            # 创建用户
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.portrait = "/static/img/avatar-1.jpg"
            # user.regtime = datetime.datetime.now()
            user.email = "*****@*****.**"
            # 将用户存到数据库
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('bp.login'))
    return render_template('register.htm', **locals())
Ejemplo n.º 15
0
def register(request):
    if request.method == 'POST':
        # 用POST数据实例化表单,表单对象会验证POST数据
        form = RegisterForm(request.POST)

        # 验证码验证
        yzm1 = request.POST.get('yzm')
        yzm2 = request.session.get('code')
        # 判定验证码是否匹配
        res = (yzm1 == yzm2)
        # 如果验证码不匹配
        if not res:
            form.errors['yzm'] = "验证码不匹配"

        if res and form.is_valid():  # 验证通过
            form.cleaned_data.pop('repassword')
            form.cleaned_data.pop('yzm')
            # form.cleaned_data.pop('phonenumber')
            User.objects.create_user(**form.cleaned_data)

            # 基础写法
            # user = User()
            # print(form.cleaned_data)
            # user.username = form.cleaned_data.get('username')
            # user.password = form.cleaned_data.get('password')
            # user.email = form.cleaned_data.get('email')
            # user.save()
            return redirect(reverse('app:index'))
        return render(request, 'app/register.html', {'form': form}, locals())
    else:
        form = RegisterForm()
        return render(request, 'app/register.html', locals())
Ejemplo n.º 16
0
def login():
    form = RegisterForm()
    if request.method == 'POST':
        username = request.values.get('username')
        password = request.values.get('password')
        user = User.query.filter(User.username == username,
                                 User.password == password).first()
        if user:
            # login_user(user)
            session["name"] = "23232"
            return redirect(url_for('bp.home'))
        else:
            flash("用户名或密码错误")
        #     return redirect(url_for("bp.login"))
    return render_template("login.htm", **locals())
Ejemplo n.º 17
0
def register(request):
    #if user is logged in,it should not access register page,it should send 'index' page
    if request.user.is_authenticated:
        return redirect('dashboard')
    #if user is not logged in,it should access register page,
    else:
        if request.method == "POST":
            form = RegisterForm(request.POST)
            #validating the form
            if form.is_valid():
                form.save()
                return redirect('login')
        else:
            form = RegisterForm()
        return render(request, 'register.html', {'form': form})
Ejemplo n.º 18
0
def register_user():
    form = RegisterForm()
    if request.method == 'POST':
        username = form.username.data
        password = form.password.data
        confirm = form.confirm.data
        email = form.email.data
        phone = form.phone.data
        if password == confirm:
            user = User(username=username,
                        password=password,
                        email=email,
                        phone=phone)
            db.session.add(user)
            db.session.commit()
            return redirect('/login/')
    return render_template('register.html', **locals())