예제 #1
0
    def post(self, request):
        # 实例化form
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            # 这里注册时前端的name为email
            user_name = request.POST.get("email", "")
            # 用户查重
            if UserProfile.objects.filter(username=user_name):
                return render(request, "register.html", {
                    "register_form": register_form,
                    "msg": "用户已存在"
                })
            pass_word = request.POST.get("password", "")

            # 实例化一个user_profile对象,将前台值存入
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name

            # 加密password进行保存
            user_profile.password = make_password(pass_word)
            user_profile.save()

            # 跳转到登录页面
            return render(request, "login.html")
        # 注册邮箱form验证失败
        else:
            return render(request, "register.html",
                          {"register_form": register_form})
예제 #2
0
파일: views.py 프로젝트: heianhu/ZhiWang
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            email = request.POST.get('email', '')
            nick_name = request.POST.get('nick_name', '')
            pass_word = request.POST.get('password', '')
            retype_password = request.POST.get('retype_password', '')
            if UserProfile.objects.filter(email=email):  # 检查是否已经注册过该用户
                return render(request, 'register.html', {'register_form': register_form, 'msg': '邮箱已存在!'})
            elif UserProfile.objects.filter(nick_name=nick_name):  # 检查是否已经注册过该用户
                return render(request, 'register.html', {'register_form': register_form, 'msg': '昵称已存在!'})
            elif pass_word != retype_password:
                return render(request, 'register.html', {'register_form': register_form, 'msg': '两次密码不一样'})
            else:
                user_profile = UserProfile()
                user_profile.nick_name = nick_name
                user_profile.username = email
                user_profile.email = email
                user_profile.password = make_password(pass_word)
                user_profile.is_active = True
                # user_profile.is_active = False  # 未激活
                # send_email_register(user_name)  # 发送邮件
                user_profile.save()

                # # 写入欢迎注册消息
                # user_message = UserMessage()
                # user_message.user = user_profile.id
                # user_message.message = '欢迎注册'
                # user_message.save()
                return render(request, 'login.html')
        else:
            return render(request, 'register.html', {'register_form': register_form})
예제 #3
0
파일: views.py 프로젝트: tarksin/social2020
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        # salt = bcrypt.gensalt()
        # hashed_password = bcrypt.hashpw(form.password.data, salt)
        code = str(uuid.uuid4())
        password64 = maxx_encode(form.password.data)
        user = User(username=form.username.data,
                    password=password64,
                    email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    change_configuration={
                        "new_email": form.email.data.lower(),
                        "confirmation_code": code
                    })

        # email the user
        body_html = render_template('mail/user/register.html', user=user)
        body_text = render_template('mail/user/register.txt', user=user)
        email(user.email, "Welcome to White History Week", body_html,
              body_text)

        user.save()
        return redirect(url_for('home_app.home'))
    return render_template('user/register.html', form=form)
예제 #4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        code = str(uuid.uuid4())
        user = User(
            username=form.username.data,
            password=hashed_password,
            email=form.email.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            change_configuration={
                "new_email": form.email.data.lower(),
                "confirmation_code": code
                }
            )
            
        # email the user
        body_html = render_template('mail/user/register.html', user=user)
        body_text = render_template('mail/user/register.txt', user=user)
        email(user.email, "Welcome to Flaskbook", body_html, body_text)
        
        user.save()
        return redirect(url_for('home_app.home'))
    return render_template('user/register.html', form=form)
예제 #5
0
    def post(self, request):

        json_data = request.body

        if json_data:
            dict_data = json.loads(json_data.decode("utf-8"))
        else:
            return to_json(errno=Code.PARAMERR,
                           errmsg=error_map[Code.PARAMERR])

        form = RegisterForm(dict_data)
        if form.is_valid():
            username = form.cleaned_data.get("username")
            mobile = form.cleaned_data.get("mobile")
            password = form.cleaned_data.get("password")

            models.User.objects.create_user(username=username,
                                            password=password,
                                            mobile=mobile)

            return to_json(errmsg="恭喜您注册成功")

        else:
            err_msg_list = []

            for item in form.errors.values():
                err_msg_list.append(item[0])
            err_str = "/".join(err_msg_list)

            return to_json(errno=Code.PARAMERR, errmsg=err_str)
예제 #6
0
def user_register(request):
    if request.method == 'GET':
        rform = RegisterForm()
        return render(request, 'register.html', context={'form': rform})
    else:
        rform = RegisterForm(request.POST)
        if rform.is_valid():
            data = rform.cleaned_data
            username = data.get('username')
            password = data.get('password')
            repassword = data.get('repassword')
            email = data.get('email')
            if password == repassword:
                password = make_password(password)
                user = User.objects.create(username=username,
                                           password=password)
                if user:
                    # 发送激活邮件
                    uid = str(uuid.uuid4()).replace('-', '')
                    cache.set(uid, user)
                    print('uid:', uid)
                    # 此时启动异步发送邮件
                    result = sendmail.delay(uid, email)

                    return HttpResponse('用户注册成功,赶快去激活吧!')
            return render(request,
                          'register.html',
                          context={
                              'form': rform,
                              'msg': '注册失败,重写注册'
                          })
예제 #7
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        code = str(uuid.uuid4())
        user = User(
            username=form.username.data,
            password=hashed_password,
            email=form.email.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            change_configuration={
                "new_email": form.email.data.lower(),
                "confirmation_code": code
                }
            )
            
        # email the user
        body_html = render_template('mail/user/register.html', user=user)
        body_text = render_template('mail/user/register.txt', user=user)
        email(user.email, "Welcome to Flaskbook", body_html, body_text)
        
        user.save()
        return "User registered"
    return render_template('user/register.html', form=form)
예제 #8
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():  #  ie passes validation
        # generate a salt (password generation key)
        salt = bcrypt.gensalt()
        # encrypt the password using the salt key
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        # Create a unique identifier to store in the change_configuration field
        code = str(uuid.uuid4())
        # Create the user object
        user = User(username=form.username.data,
                    password=hashed_password,
                    email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    bio=form.bio.data,
                    change_configuration={
                        "new_email": form.email.data.lower(),
                        "confirmation_code": code
                    })
        # Email verification to the user
        body_html = render_template('mail/user/register.html', user=user)
        body_text = render_template('mail/user/register.txt', user=user)

        email(user.email, 'Welcome to Flaskbook', body_html, body_text)

        # save the user to the database
        user.save()
        return 'User registered'

    return render_template('user/register.html', form=form)
예제 #9
0
파일: views.py 프로젝트: levvli/ws
 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'请访问该链接,完成用户验证,该链接一个小时有效',
             '/'.join([settings.DOMAIN, 'activate', token])
         ])
         # send_mail(u'注册用户验证信息', message, settings.EMAIL_HOST_USER, [email], fail_silently=False)
         send_register_email
         send_register_email(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
     })
예제 #10
0
def register_view(request):
    if request.method == "POST":
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            username = register_form.cleaned_data['username']
            first_name = register_form.cleaned_data['first_name']
            last_name = register_form.cleaned_data['last_name']
            password = register_form.cleaned_data['password']
            email = register_form.cleaned_data['email']
            old_user = User.objects.filter(Q(username=username))
            if old_user is not None and len(old_user) > 0:
                print("user is not none")
                return HttpResponse(json.dumps({"status": -1}),
                                    content_type="application/json")
            user = User.objects.create_user(username=username,
                                            email=email,
                                            password=password,
                                            first_name=first_name,
                                            last_name=last_name)
            user.save()
            weblog = Weblog.objects.create(user=user,
                                           weblog_name="default",
                                           is_default=True)
            weblog.save()

            return HttpResponse(json.dumps({"status": 0}),
                                content_type="application/json")

    return HttpResponse(json.dumps({"status": -1}),
                        content_type="application/json")
예제 #11
0
def user_register(request):
    if request.method == 'GET':
        return render(request, 'user/register.html')
    else:
        rform = RegisterForm(request.POST)  # 使用form获取数据
        if rform.is_valid():  # 进行数据的校验
            # 从干净的数据中取值
            username = rform.cleaned_data.get('username')
            email = rform.cleaned_data.get('email')
            mobile = rform.cleaned_data.get('mobile')
            password = rform.cleaned_data.get('password')
            if not UserProfile.objects.filter(
                    Q(username=username) | Q(mobile=mobile)).exists():
                # 注册到数据库中
                password = make_password(password)  # 密码加密
                user = UserProfile.objects.create(username=username,
                                                  password=password,
                                                  email=email,
                                                  mobile=mobile)
                if user:
                    return HttpResponse('注册成功')
            else:
                return render(request,
                              'user/register.html',
                              context={'msg': '用户名或者手机号码已经存在!'})
        return render(request,
                      'user/register.html',
                      context={'msg': '注册失败,重新填写!'})
예제 #12
0
def register(request):
    if request.method == 'GET':
        form = RegisterForm()
        return render(request, 'register.html', {'form': form})
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            email = form.cleaned_data['email']
            raw_password = form.cleaned_data['password1']
            user = User.objects.create_user(name=name, email=email, password=raw_password)

            token = default_token_generator.make_token(user)
            user.token = token
            user.save()
            mail_subject = 'Activate your BB Dash account'
            current_site = get_current_site(request)
            message = render_to_string('activation_email.html',
                                       {'user': user, 'domain': current_site.domain,
                                        'uid': urlsafe_base64_encode(force_bytes(user.id)).decode(),
                                        'token': token})
            email = EmailMessage(mail_subject, message, to=[user.email])
            email.send()
            messages.add_message(request, messages.INFO, 'An email has been sent to your email address. Please click on'
                                                         ' the link to activate your account.')
        return redirect('/user/login')
예제 #13
0
 def post(self, request):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         email = request.POST.get("email", '')
         if UserProfile.objects.filter(email=email):
             return render(request, 'register.html', {
                 'register_form': register_form,
                 'msg': '用户已存在'
             })
         pass_word = request.POST.get("password", '')
         user_name = request.POST.get("username", '')
         if UserProfile.objects.filter(username=user_name):
             return render(request, 'register.html', {'msg': '此用户名已被使用'})
         user_profile = UserProfile()
         user_profile.username = user_name
         user_profile.email = email
         user_profile.is_active = False
         user_profile.password = make_password(pass_word)
         user_profile.save()
         send_email_register(email, 'register')
         return render(request, 'login_user.html',
                       {'msg': "发送邮件成功,请注意查收..."})
     else:
         email = request.POST.get("email", '')
         return render(request, 'register.html', {
             'email': email,
             'register_form': register_form
         })
예제 #14
0
 def test_form_not_valid_email(self):
     params = dict(username='******',
                   email="",
                   password="******",
                   password2="1111")
     form = RegisterForm(params)
     self.assertFalse(form.is_valid())
예제 #15
0
def register(request):
    form = RegisterForm(request.POST or None)
    context = {'form': form}
    if form.is_valid():
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        email = form.cleaned_data.get('email')
        first_name = form.cleaned_data.get('first_name')
        last_name = form.cleaned_data.get('last_name')
        instance = User.objects.create_user(username=username,
                                            email=email,
                                            password=password,
                                            first_name=first_name,
                                            last_name=last_name,
                                            is_active=False,
                                            is_staff=False,
                                            is_superuser=False)
        request.session['code'] = random.randint(111111, 999999)
        message = email_creation(
            instance.first_name + ' ' + instance.last_name,
            request.session['code'])
        send_mail(
            'Activation code',
            message,
            '*****@*****.**',
            [instance.email],
            fail_silently=False,
        )
        return redirect('user:verfication', username=instance.username)
    return render(request, 'user/register.html', context)
예제 #16
0
 def test_form_not_valid_password(self):
     params = dict(username='',
                   email="*****@*****.**",
                   password="******",
                   password2="1111")
     form = RegisterForm(params)
     self.assertFalse(form.is_valid())
예제 #17
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST or None)
        form.need_confirm = False
        if form.is_valid():
            clean_data = form.cleaned_data
            email = clean_data.get('email', None)
            password = clean_data.get('password', None)
            validate_code = clean_data.get('validate_code', None)
            invite_code = clean_data.get('invite_code', None)

            user = UserModel.objects.filter(email=email)
            if user:
                return Response(status=status.HTTP_409_CONFLICT)
            else:
                user = UserModel()
                user.email = email
                encode_password = make_password(password)
                user.password = encode_password
                records = MailCodeModel.objects.filter(code=validate_code)
                if records:
                    user.active = True

                invitation = InvitationCodeModel.objects.filter(
                    code=invite_code, active=False)
                if invitation:
                    invitation.active = True
                    user.invite = True
                    invitation.save()
                user.save()
                return Response(status=status.HTTP_200_OK)
    return Response(status=status.HTTP_400_BAD_REQUEST)
예제 #18
0
 def test_form_valid(self):
     params = dict(username='******',
                   email="*****@*****.**",
                   password="******",
                   password2="1111")
     form = RegisterForm(params)
     self.assertTrue(form.is_valid())
예제 #19
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            username = request.POST.get('email', '')
            if UserProfile.objects.filter(email=username):
                return render(request, 'user/register.html', {
                    'register_form': register_form,
                    'msg': '用户已经存在'
                })
            password = request.POST.get('password', '')
            user_profile = UserProfile()
            user_profile.username = username
            user_profile.email = username
            user_profile.is_active = False
            user_profile.password = make_password(password)
            user_profile.save()

            # 写入欢迎注册信息
            user_message = UserMessage()
            user_message.user = user_profile.id
            user_message.message = '欢迎光临本站'
            user_message.save()

            send_register_email(username, 'register')
            return render(request, 'user/login.html', {})
        else:
            return render(request, 'user/register.html',
                          {'register_form': register_form})
예제 #20
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        usr = insert_user(name=form.name.data,
                          surname=form.surname.data,
                          email=form.email.data,
                          password=form.password.data,
                          dateofbirth=form.dateofbirth.data,
                          university=form.university.data,
                          course=form.course.data)
        if isinstance(usr, (int, long)):
            return redirect(url_for("user.register"))
        token = generate_confirmation_token(usr.email)
        confirm_url = url_for('user.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(usr.email, subject, html)

        login_user(usr)

        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for("main.home"))

    return render_template('user/register.html', form=form)
예제 #21
0
def register():
    form = RegisterForm()
    message = None
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        code = str(uuid.uuid4().hex)
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        user = User(username=form.username.data,
                    password=hashed_password,
                    email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    bio=form.bio.data,
                    change_configuration={
                        "new_email": form.email.data.lower(),
                        "confirmation_code": code
                    })
        user.save_database()
        # send email
        html_body = render_template('mail/user/register.html', user=user)
        html_text = render_template('mail/user/register.txt', user=user)
        email(user.change_configuration['new_email'], "Confirm your email", html_body, html_text)
        message = "Please Check you email to complete registration."
        return render_template('user/register.html', form=form, message=message)
    return render_template('user/register.html', form=form, message=message)
예제 #22
0
def register(request):
    if request.method == "POST":
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            username = register_form.cleaned_data['username']
            password1 = register_form.cleaned_data['password1']
            password2 = register_form.cleaned_data['password2']
            email = register_form.cleaned_data['email']
            if password1 != password2:
                message = "You need to enter the same password twice!"
                return render(request, 'user/register.html', locals())
            else:
                same_name_user = User.objects.filter(name=username)
                if same_name_user:
                    message = 'The same user name exists, please change you username!'
                    return render(request, 'user/register.html', locals())
                same_email_user = User.objects.filter(email=email)
                if same_email_user:
                    message = 'The email account has been used, please change another one!'
                    return render(request, 'user/register.html', locals())

                new_user = User.objects.create()
                new_user.name = username
                new_user.password = password1
                new_user.email = email
                new_user.save()
                return redirect(reverse('index'))
    register_form = RegisterForm()
    return render(request, 'user/register.html', locals())
예제 #23
0
def register(request):
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password")

            new_user = User(username=username)
            new_user.set_password(password)
            new_user.save()

            messages.success(request, 'Successfully Registered')
            login(request, new_user)

            return redirect("index")
        else:
            context = {
                "form": form
            }
            return render(request, "register.html", context)

    else:
        form = RegisterForm()
        context = {
            "form": form
        }
        return render(request, "register.html", context)
예제 #24
0
def register():
    form = RegisterForm()
    if request.args.get('storecode'):
        session['temp_storecode'] = request.args.get('storecode')

    # store storecode in temp_storecode session
    if form.validate_on_submit():
        code = str(uuid.uuid4())
        hash_pwd = generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    password=hash_pwd,
                    email=form.email.data,
                    change_configuration={
                        "new_email": form.email.data.lower(),
                        "confirmation_code": code
                    },
                    email_confirmed=True)

        if session.get('temp_storecode'):
            body_html = render_template(
                'mail/user/confirm.html',
                user=user,
                storecode=session.get('temp_storecode'))
            body_text = render_template(
                'mail/user/confirm.txt',
                user=user,
                storecode=session.get('temp_storecode'))
        else:
            body_html = render_template('mail/user/confirm_n.html', user=user)
            body_text = render_template('mail/user/confirm_n.txt', user=user)
        email(user.email.lower(), "Email confirmation", body_html, body_text)
        user.save()
        return redirect(
            url_for('user_app.awaiting', user_email=form.email.data.lower()))
    return render_template('user/register.html', form=form)
예제 #25
0
파일: views.py 프로젝트: DanAurea/Webcraft
def register(request):
    form = RegisterForm(request.POST or None)
    valueButton = "S'inscrire"
    link = "<a id=\"link\" href=\"login\">Connectez-vous</a>"

    error = None
    if form.is_valid():
        account = form.cleaned_data['account']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        avatarName = form.cleaned_data['avatarName']
        model = form.cleaned_data['model']

        #verifier si utilisateur n'existe pas déjà dans la bdd
        try:
            newUser = User.objects.create_user(account, email, password)
            newPlayer = Player.objects.create(
                user=newUser,
                position="50,50,50",
                role=Role.objects.get(name="user"))
            newAvatar = Avatar.objects.create(name=model)
            newAvatarPlayer = AvatarPlayer.objects.create(
                avatar_id=newAvatar,
                player_id=newPlayer,
                avatar_name=avatarName)
            return redirect(reverse("user:login"), permanent=True)
        except IntegrityError:
            error = "L'utilisateur existe déjà"

    return render(request, 'user/baseForm.html', locals())
예제 #26
0
def home_view(request):

    if not request.user.is_authenticated:

        #Getting a random contest to be used in steps section
        count = Contest.objects.count()
        if count > 0:
            random_index = randint(0,count-1)
            random_contest = Contest.objects.all()[random_index]
        else:
            random_contest = None

        #Sign up form
        form = RegisterForm(data=request.POST or None)
        if form.is_valid():
            user = form.save(commit=False)
            password = form.cleaned_data.get('password1')
            user.set_password(password)
            user.save()
            messages.success(request, "Thank you for joining our community. Explore the best photos on Photash!", extra_tags="alert-success")

            #setting language by the IP
            client = geoip2.webservice.Client(132292, '9uNrE6xTWGHX')
            ip = get_ip(request)
            response = client.city('46.218.85.101')  # Uzak server'a yüklendiğinde burdaki harcoded ip yerine ip yazılacak. Şu an yazılınca 127.0.0.1 hata çıkartıyor o yüzden yazılmadı
            if (response.country.iso_code == "TR"):
                user.profile.languagePreference ="tr"
                user.save()

            # mail verification
            token = account_activation_token.make_token(user)
            uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()
            send_mail(
                'Please confirm your photash account',
                'Click the link belox \n http://127.0.0.1:8000/user/activate/{}/{}'.format(uid, token),
                '*****@*****.**',
                [user.email, ],
                fail_silently=False,
            )
            new_user = authenticate(username=user.username, password=password)
            login(request, new_user)


        context={
            'form': form,
            'random_contest': random_contest
        }

        # Guestler için session kontrolü
        # Session'da language belirlenmemiş ise önce belirleyelim
        if "language" not in request.session:
            set_session_for_language_according_to_IP(request)

        if (request.session['language'] == "tr"):
            return render(request, 'home/home-tr.html', context)
        else:
            return render(request, 'home/home.html', context)
    else:
        return render(request, 'home/timeline.html')
예제 #27
0
def register():
    form=RegisterForm()
    if form.validate_on_submit():
        salt=bcrypt.gensalt(10)
        hashed_password=bcrypt.hashpw(form.password.data,salt)
        user = User(username=form.username.data,password=hashed_password,email=form.email.data,first_name=form.first_name.data,last_name=form.last_name.data)
        user.save()
        return 'User registered'
    return render_template('user/register.html',form=form)
예제 #28
0
파일: views.py 프로젝트: jsye/shop
 def post(self, request):
     res = request.POST
     form = RegisterForm(res)
     data = form.is_valid()
     if data:
         form.save()
         return redirect(reverse('user:login'))
     else:
         return render(request, 'user/reg.html', {"form": form})
예제 #29
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():

            user = form.save()
            request.session['uid'] = user.id

    return render(request,'user/register.html',{})
예제 #30
0
파일: views.py 프로젝트: BJ-1803-B4/bbs
def register_handler(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            User.objects.create(form.cleaned_data.get('username'),
                                form.cleaned_data.get('password'))
            return redirect('login')
        else:
            return render(request, 'register.html', {'form': form})
    raise Http404
예제 #31
0
파일: views.py 프로젝트: intuij/Flasky-Blog
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Register Success!')
        return redirect(url_for('login'))
    return render_template('user/register.html', form=form)
예제 #32
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        fullname = form.fullname.data
        username = form.username.data
        password = form.password.data
        email = form.email.data
        is_admin = False
        user = User(fullname, username, password, email, is_admin)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('dashboard/admin'))
    return render_template('user/register.html', form=form)
예제 #33
0
def register():
    """Register view."""
    form = RegisterForm()
    if form.validate_on_submit():
        flash("Username registered.", "success")
        user.create_user(
            first_name=form.first_name.data,
            second_name=form.second_name.data,
            phone=form.phone.data,
            role=form.role.data,
            username=form.username.data,
            password=form.password.data,
            email=form.email.data
        )
        return redirect(url_for('index'))
    return render_template('user/register.html', form=form)
예제 #34
0
def register():
    if get_current_user().is_anonymous():
        register_form = RegisterForm()
        if register_form.validate_on_submit():
            create_user(
                first_name=register_form.first_name.data,
                last_name=register_form.last_name.data,
                username=register_form.username.data,
                email=register_form.email.data,
                password=generate_password_hash(register_form.password.data)
            )
            return redirect(url_for('login'))
        else:
            return render_template('register.html',
                                   register_form=register_form
                                   )
    else:
        flash("You are already an user.")
        return redirect(url_for('dashboard'))