Пример #1
0
def register(request, openid):
    if len(openid) == 0:
        return HttpResponse('error')
    if request.method == 'POST':
        form = RegistForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            phonenumber = form.cleaned_data['phonenumber']
            code = form.cleaned_data['verification_code']
            try:
                record = SendDynamicRecord.objects.get(is_valid=True, phonenumber=phonenumber, password=code, openid=openid)
            except ObjectDoesNotExist:
                form = RegistForm(initial={'name': name, 'phonenumber': phonenumber})
                return render_to_response('register.html', {'form': form, 'code_error': True})
            else:
                record.is_valid = False
                record.save()
                u = User(openid=openid, name=name, phonenumber=phonenumber)
                u.save()
                return HttpResponseRedirect(reverse('register_success'))
    else:
        try:
            u = User.objects.get(openid=openid)
        except ObjectDoesNotExist:
            form = RegistForm()
            return render_to_response('register.html', {'form': form})
        else:
            return HttpResponseRedirect(reverse('register_already'))
Пример #2
0
def register():
    form = RegistForm()
    error = None
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        repassword = request.form['repassword']
        if User.query.filter_by(username=username).all():
            error = '用户名已存在'
            return render_template('register.html', form=form, error=error)
        if username is None:
            error = 'Invalid username'
        if password != repassword:
            error = '密码不一致'
            return render_template('register.html', form=form, error=error)
        else:
            form.validate_on_submit()
            data = form.data
            user = User(
                username = data["username"],
                password = generate_password_hash(data["password"]),
                addtime = datetime.now()
            )
            db.session.add(user)
            db.session.commit()
            flash("注册成功!", "OK")
            return redirect(url_for('login'))
    return render_template("register.html", form=form, error=error)
Пример #3
0
def regist():
    if flask.request.method == 'GET':
        return flask.render_template('regist.html')
    else:
        form = RegistForm(flask.request.form)
        if form.validate():
            email = form.email.data
            username = form.username.data
            password = form.password1.data
            confirmed = False
            aboutme = "这个人很懒。。。"
            user = UserModel(email=email,
                             username=username,
                             password=password,
                             confirmed=confirmed,
                             aboutme=aboutme)
            db.session.add(user)
            db.session.commit()
            token = user.generate_confirmation_token()
            send_email(user.email,
                       'confirm your account',
                       'confirm',
                       user=user,
                       token=token)
            flash('A confimed email has been sent via email')
            return flask.redirect(flask.url_for('login'))
Пример #4
0
def regist():
    form = RegistForm()
    if current_user.is_authenticated:
        return render_template('user.html', user=current_user)
    elif request.method == 'POST' and form.validate_pwd(
    ) and form.validate_on_submit():
        if not form.agreed():
            flash('If you disagree the protocol, you can not use our product')
            return render_template('regist.html', form=form)
        nikename = form.nikename.data
        username = form.username.data
        password = form.password.data
        email = form.email.data
        phone = form.phone.data
        user = User(
            username=username,
            nikename=nikename,
            email=email,
            phone=phone,
        )
        user.password = user.set_password(password)
        user.save()
        flash('regist success, you can login now')
        return redirect('login')
    return render_template('regist.html', form=form)
Пример #5
0
def user_regist():
    form = RegistForm()
    if form.validate_on_submit():
        user = User()
        user.name = form.user_name.data
        user.pwd = form.user_pwd.data
        user.email = form.data['user_email']
        user.age = form.user_edge.data
        user.birthday = form.data["user_birthday"]
        # filestorage = form.user_face.data
        filestorage = request.files["user_face"]
        print(filestorage)
        user.face = filestorage.filename
        print(user.face)
        # 查看用户名是否已经存在
        user_x = query_user_by_name(user.name)
        if user_x:
            flash("用户名已经存在!", category='err')
            return render_template('user_regist.html', form=form)
        # 如果用户不存在,执行插入操作
        insert_user_to_db(user)
        # 保存用户头像文件
        filestorage.save(filestorage.filename)
        flash("用户注册成功!", category='ok')
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html', form=form)
Пример #6
0
def user_regist():
    regForm = RegistForm()
    if regForm.validate_on_submit():
        if not check_files_ext([regForm.user_face.data.filename],
                               ALLOWED_IMAGE_EXT):
            flash(message=u'上传的图片格式不支持!', category='error')
            return render_template('user_regist.html', form=regForm)
        user = User()
        user.name = request.form['user_name']
        user.pwd = request.form['user_pwd']
        user.email = request.form['user_email']
        user.age = request.form['user_age']
        user.birthday = request.form['user_birthday']
        f = request.files['user_face']
        user.face = change_filename_to_uuid(f.filename)
        user_x = query_user_by_name(user.name)
        if user_x:
            flash(u"用户名已经存在!", category='error')
            return render_template('user_regist.html', form=regForm)
        insert_user_to_db(user)
        userfolder = os.path.join(app.config["UPLOAD_FOLDER"], user.name)
        if not os.path.exists(userfolder):
            os.mkdir(userfolder, os.O_RDWR)
        f.save(os.path.join(userfolder, user.face))
        flash(u"注册成功", category='ok')
        return redirect(url_for("user_login", username=user.name))
    return render_template('user_regist.html', form=regForm)
Пример #7
0
def regist():
    if request.method == 'GET':
        return render_template('regist.html')
    else:
        form = RegistForm(request.form)
        if form.validate():
            return "注册成功"
        else:
            return form.errors
Пример #8
0
 def post(self):
     form = RegistForm(request.form)
     if form.validate():
         email = form.email.data
         username = form.username.data
         password = form.password.data
         deposit = form.deposit.data
     else:
         print(form.errors)
         return "注册失败"
Пример #9
0
def regist():
    if request.method == 'GET':
        return render_template('regist.html')
    else:
        form = RegistForm(request.form)
        if form.validate():
            return 'success'
        else:
            print(form.errors)
            return 'fail'
Пример #10
0
def regist():
    if request.method == 'GET':
        return render_template('regist.html')
    else:
        form = RegistForm(request.form)
        if form.validate():
            return "success"
        else:
            # 打印验证的错误信息
            print(form.errors)
            return "fail"
Пример #11
0
def regist():
    if flask.request.method == 'GET':
        return flask.render_template('regist.html')
    else:
        form = RegistForm(flask.request.form)
        if form.validate():
            telephone = form.telephone.data
            username = form.username.data
            password = form.password1.data
            user = UserModel(telephone=telephone,username=username,password=password)
            db.session.add(user)
            db.session.commit()
            return flask.redirect(flask.url_for('login'))
Пример #12
0
 def post(self):
     form = RegistForm(request.form)
     if form.validate():
         username = form.username.data
         password = form.password.data
         user = User.query.filter(User.username == username).first()
         if user:
             form.username.errors.append('该用户已注册!')
             return render_template('regist.html', form=form)
         user = User(username=username, password=password)
         db.session.add(user)
         db.session.commit()
         return redirect(url_for('index'))
     return render_template('regist.html', form=form)
Пример #13
0
 def post(self):
     form = RegistForm(request.form)
     if form.validate():
         email = form.email.data
         username = form.username.data
         password = form.password.data
         user = User(email=email, username=username,
                     password=password)
         db.session.add(user)
         db.session.commit()
         return '注册成功'
     else:
         print(form.errors)
         return 'error'
Пример #14
0
def create():
    if request.method == "POST":
        reg_code = request.form.get("code","").strip().lower()
        if reg_code != session["code"].strip().lower():
            errors = [u"验证码不正确"]
            return render_template("regist.html",**locals())
        form = RegistForm(request.form)
        if form.validate():
            try:
                user_id = serv.regist(form.login_name.data,form.password.data)
                session["user_id"] = user_id
                return redirect(url_for('user.info'))
            except DuplicateException,e:
                g.db.rollback()
                errors = [e.message,]
        else:
            errors = [v[0] for k,v in form.errors.iteritems()]
Пример #15
0
def regist():
    form = RegistForm()
    if form.validate_on_submit():
        if User.query.filter_by(email=form.email.data).first():
            flash('Email已被註冊', 'error')
        else:
            if User.query.filter_by(username=form.username.data).first():
                flash('使用者已被註冊', 'error')
            else:
                user = User(email=form.email.data,
                            username=form.username.data,
                            password=form.password.data,
                            realname=form.realname.data)
                db.session.add(user)
                db.session.commit()
                flash('註冊成功!', 'success')
                return redirect(url_for('login'))
    return render_template('auth/regist.html', form=form)
Пример #16
0
    def post(self):

        form = RegistForm(request.form)

        if form.validate():
            username = form.username.data
            userpass = form.userpass.data

            user = User(user_name=username, user_pass=userpass)

            db.session.add(user)
            db.session.commit()

            return render_template(url_for('login'))

        else:
            self.error = 'regist error'
            return render_template('regist.html', error=self.error)
Пример #17
0
def register(request):
	if request.method == 'GET':
		return render(request,'register.html')
	else:
		form = RegistForm(request.POST,request.FILES)   # request.FILES  上传文件需要
		if form.is_valid():
			username = form.cleaned_data.get('username',None)
			password = form.cleaned_data.get('password',None)
			email = form.cleaned_data.get('email',None)
			repassword = form.cleaned_data.get('repassword',None)
			avatar = form.cleaned_data.get('avatar',None)                   #获取上传的文件
			if password == repassword:
				user = UserModel(username=username, password=password, email=email, avatar=avatar)
				user.save()
				html = 'username:%s, password:%s, email:%s' %(username, password, email)
			return HttpResponse(html)
		else:
			return render(request,'register.html',{'errors':form.errors.as_json()})
Пример #18
0
 def post(self):
     form = RegistForm(flask.request.form, csrf_enabled=False)
     if form.validate():
         email = form.email.data
         username = form.username.data
         password = form.password.data
         deposit = form.deposit.data or 0
         user = User(email=email,
                     username=username,
                     password=password,
                     deposit=deposit)
         db.session.add(user)
         db.session.commit()
         # 跳转到主页
         return flask.redirect(flask.url_for('index'))
     else:
         print(form.errors)
         return u'注册失败'
Пример #19
0
 def post(self):
     form = RegistForm(request.form)
     if form.validate():
         email = form.email.data
         username = form.username.data
         password = form.password.data
         deposit = form.deposit.data
         user = User(email=email,
                     username=username,
                     password=password,
                     deposit=deposit)
         db.session.add(user)
         db.session.commit()
         return '注册成功!'
     else:
         print(form.errors)
         # {"email":['邮箱不正确','邮箱长度不够']}
         return '注册失败!'
Пример #20
0
def register_demo(request):
	if request.method == 'GET':
		form = RegistForm()
		return render(request,'register_demo.html', {'form':form})
	else:
		form = RegistForm(request.POST)
		if form.is_valid():
			username = form.cleaned_data.get('username',None)
			password = form.cleaned_data.get('password',None)
			email = form.cleaned_data.get('email',None)
			repassword = form.cleaned_data.get('repassword',None)
			if password == repassword:
				user = UserModel(username=username, password=password, email=email)
				user.save()
				html = 'username:%s, password:%s, email:%s' %(username, password, email)
			return HttpResponse(html)
		else:
			return HttpResponse('failure')
Пример #21
0
def user_regist():  # 注册
    form = RegistForm()
    if form.validate_on_submit(
    ):  # 检查提交方式是否为post 验证forms.py定义的validators 验证是否通过
        # print("form", form.user_name.data)
        # print("form", form.data)
        # print("form", form.data["user_name"])
        # print("request.form", request.form)
        user = User()
        # user.name = request.form["user_name"]
        user.name = form.user_name.data
        # user.pwd = request.form["user_pwd"]
        user.pwd = form.user_pwd.data
        # user.age = request.form["user_age"]
        user.age = form.user_age.data
        # user.birthday = request.form["user_birthday"]
        user.birthday = form.user_birthday.data
        # user.email = request.form["user_email"]
        user.email = form.user_email.data
        # user.face = request.form["user_face"]
        # user.face = form.user_face.data
        # filerstorage=form.user_face.data
        filerstorage = request.files["user_face"]  # 获取头像文件
        user.face = filerstorage.filename

        # 查看用户是否存在
        user_one = query_user_by_name(user.name)
        if user_one:
            # 返回注册界面,重新注册
            flash("用户名已存在!", category="err"
                  )  # Flashes a message to the next request 闪现一条消息到下一次消息请求

            return render_template("user_regist.html", form=form)

        # 如果不存在执行插入操作
        # 插入一条数据
        instert_user_to_db(user)
        # 保存用户头像文件
        filerstorage.save(user.face)
        flash("注册成功!", category="ok")
        # username作为查询参数带到url中去
        ## 重定向页面 生成url 执行 user_login 函数 跳转到登录界面
        return redirect(url_for("user_login", username=user.name))
    return render_template("user_regist.html", form=form)
Пример #22
0
def create():
    if request.method == "POST":
        reg_code = request.form.get("code", "").strip().lower()
        if reg_code != "orz!":
            if reg_code != session["code"].strip().lower():
                errors = [u"验证码不正确"]
                return render_template("regist.html", **locals())
        form = RegistForm(request.form)
        if form.validate():
            try:
                user_id = serv.regist(form.login_name.data, form.password.data)
                session["user_id"] = user_id
                return redirect(url_for('user.info'))
            except DuplicateException, e:
                g.db.rollback()
                errors = [
                    e.message,
                ]
        else:
            errors = [v[0] for k, v in form.errors.iteritems()]
Пример #23
0
def register():
    error = None
    if current_user.is_anonymous:
        form = RegistForm(request.form)
        if request.method == "POST" and form.validate():
            try:
                user = DBUser(username=form.username.data,
                              email=form.email.data,
                              password=bcrypt.hashpw(
                                  form.password.data.encode("utf-8"),
                                  bcrypt.gensalt()))
                db.session.add(user)
                db.session.commit()
                return redirect(url_for("login"))
            except:
                # need to improve this error handling
                error = "Username or email already in use."
        return render_template("register.html", form=form, error=error)
    else:
        return redirect(url_for("home"))
Пример #24
0
def regist():
    form = RegistForm()
    if request.method == 'GET':
        return render_template('regist.html', form=form)
    if request.method == 'POST':
        user = User.query.filter_by(email=form.email.data).first()
        if form.validate_on_submit() and not user:
            user = User(name=form.name.data, email=form.email.data, authentication=False)
            user.set_passwd(form.passwd.data)
            db.session.add(user)
            db.session.commit()
            login_user(user)
            next = request.args.get('next') or url_for('index')
            flash('请查收您的注册邮件以激活账号')
            return redirect(next)
        else:
            if user:
                flash('当前邮箱已注册,请直接登录')
                return redirect('login')
            else:
                flash('请检查输入重试')
                return render_template('regist.html', form=form)
Пример #25
0
def register(req):
    errs = ''
    if req.method == "POST":
        form = RegistForm(req.POST, req.FILES)
        if form.is_valid():
            #user表 注册
            form_data = form.cleaned_data
            username = form_data['username']
            isname = models.User.objects.filter(username=username)
            if len(isname) > 0:
                username = str(username)
                errs = "用户名 " + username + " 已存在"
                return render(req, 'register.html', {'err_userame': errs})

            password = form_data['password']
            repassword = form_data['repassword']

            if password != repassword:
                errs = "两次输入密码不一致"
                return render(req, 'register.html', {'err_password': errs})

            email = form_data['email']
            user = User.objects.create_user(username, email, password)
            user.save()

            #UserProfile表增加 昵称
            userprofile = models.UserProfile()
            userprofile.name = form_data['name']
            userprofile.user_id = user.id
            userprofile.save()
            ok_msg = "注册成功,马上登录"
            return render(req, 'login.html', {
                'ok': ok_msg,
                'username': username
            })
        else:
            errs = form.errors
    return render(req, 'register.html', {'err_msg': errs})
Пример #26
0
def register(request, openid):
    if len(openid) == 0:
        return HttpResponse('error')
    if request.method == 'POST':
        form = RegistForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            phonenumber = form.cleaned_data['phonenumber']
            code = form.cleaned_data['verification_code']
            try:
                record = SendDynamicRecord.objects.get(is_valid=True,
                                                       phonenumber=phonenumber,
                                                       password=code,
                                                       openid=openid)
            except ObjectDoesNotExist:
                form = RegistForm(initial={
                    'name': name,
                    'phonenumber': phonenumber
                })
                return render_to_response('register.html', {
                    'form': form,
                    'code_error': True
                })
            else:
                record.is_valid = False
                record.save()
                u = User(openid=openid, name=name, phonenumber=phonenumber)
                u.save()
                return HttpResponseRedirect(reverse('register_success'))
    else:
        try:
            u = User.objects.get(openid=openid)
        except ObjectDoesNotExist:
            form = RegistForm()
            return render_to_response('register.html', {'form': form})
        else:
            return HttpResponseRedirect(reverse('register_already'))
Пример #27
0
def regist(request, activate_key):
    act = list(
        ActivateKey.objects.filter(activate_key__exact=activate_key,
                                   activated=False))
    if not act:
        raise Http404()
    act = act[0]
    if request.method == 'POST':
        new_data = request.POST.copy()
        new_data.update({'email': act.email})
        form = RegistForm(new_data)
        if form.is_valid():
            user = form.save()
            user.email = act.email
            user.save()
            act.activated = True
            act.save()
            #return HttpResponseRedirect(URL_HOME)
            return HttpResponseRedirect(reverse('login'))
    else:
        form = RegistForm()
    return render_to_response('event/regist.html',
                              context_instance=RequestContext(
                                  request, {'form': form}))
Пример #28
0
def register():
    form = RegistForm()
    return render_template("register.html", form=form)
Пример #29
0
 def get(self):
     form = RegistForm()
     return render_template('regist.html', form=form)