Esempio n. 1
0
def registration_view(request):
    cart = try_session(request)
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        new_user = form.save(commit=False)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = form.cleaned_data['first_name']
        new_user.last_name = form.cleaned_data['last_name']
        phone = Phone(user= username, phone =form.cleaned_data['phone'] )
        new_user.email = form.cleaned_data['email']
        new_user.save()
        phone.save()
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse('base'))
    c = count(cart)
    context = {
        'c': c,
        'cart': cart,
        'categories': get_categories(),
        'form': form,
    }
    return render(request,'registration.html',context)
Esempio n. 2
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            sexe = form.cleaned_data['sexe']
            user_address = form.cleaned_data['user_address']
            type = form.cleaned_data['type']

            user = User.objects.create_user(username=username,
                                            password=password,
                                            email=email,
                                            last_name=last_name,
                                            first_name=first_name)
            user = authenticate(username=username, password=password)
            login(request, user)
            if type == 'candidate':
                user_account(user=user, user_address=user_address,
                             gender=sexe).save()
                return jobs(request)
            else:
                recruiter(user=user, user_address=user_address,
                          gender=sexe).save()
                return redirect('main:complete-company')

    return render(request=request,
                  template_name='main/signin.html',
                  context={'form': RegistrationForm})
Esempio n. 3
0
def index(request):
    """
    If a user is logged in, returns the main index of all of a user's
    clipboard history sorted with the most recent at the top.
    Paginates the data using django-pagination, currently uses
    Twitter style pagination.

    If a user is not logged in, just offers up a registration/login form.
    """
    clippings = Clipping.objects.filter(
        created_by=request.user.id).order_by("-time")
    if request.user.is_authenticated():
        context = {'clippings': clippings}
        if request.is_ajax():
            return render(request, 'pagination.html', context,)
        else:
            return render(request, 'index.html', context)
    else:
        form = RegistrationForm()
        context = {'form': form}
        if request.method == 'POST':
            form = RegistrationForm(request.POST)
            if form.is_valid():
                user = User.objects.create_user(
                    username=form.cleaned_data['username'],
                    email=form.cleaned_data['email'],
                    password=form.cleaned_data['password']
                )
                user.save()
                return redirect(reverse('login'))
            else:
                return render(request, 'index.html', {'form': form})
        else:
            return render(request, 'index.html', context)
Esempio n. 4
0
def User_Registration(request):

    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data["username"],
                email=form.cleaned_data["email"],
                password=form.cleaned_data["password"],
            )
            user.save()
            #                    users = user.get.profile()
            #                    users.name = form.cleaned_data['name']
            #                    users.birthday = form.cleaned_data['birthday']
            #                    users.save()
            users = Users(user=user, name=form.cleaned_data["name"], birthday=form.cleaned_data["birthday"])
            users.save()
            return HttpResponseRedirect("/")
        else:
            return render_to_response("RegisterUser.html", {"form": form}, context_instance=RequestContext(request))
    else:
        """ user is not submitting the form, show them a blank registration form """
        form = RegistrationForm()
        context = {"form": form}
        return render_to_response("RegisterUser.html", context, context_instance=RequestContext(request))
Esempio n. 5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()

    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        # user = User(username = form.username.data, first_name = form.first_name.data, last_name = form.last_name.data,
        #     email = form.email.data, password = hashed_password)

        flask.session['user'] = form.username.data
        flask.session['first_name'] = form.first_name.data
        flask.session['last_name'] = form.last_name.data
        flask.session['email'] = form.email.data
        flask.session['password'] = hashed_password

        username = form.username.data

        flash(f'Please set up your profile to create your account.', 'success')

        return redirect(url_for('profile_creation', username=username))

    return render_template('register.html', title='Register', form=form)
Esempio n. 6
0
def register(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        register_form = RegistrationForm(request.POST)  # create form object
        if register_form.is_valid():
            register_form.save()
            username = request.POST['username']
            password = request.POST['password1']
            user = authenticate(username=username, password=password)
            if user is not None:
                auth.login(request, user)

            html_register = get_template('email_register.html', )
            register_html = Context({'first_name': request.user.first_name, 'last_name': request.user.last_name})
            html_content = html_register.render(register_html)
            subject = 'Regisration'
            from_email = '*****@*****.**'
            to = auth.get_user(request).email
            msg = EmailMultiAlternatives(subject, '', from_email, [to])
            msg.attach_alternative(html_content, "text/html")
            try:
                msg.send()
            except:
                pass
            return redirect('index')
        else:
            args['custom_error'] = register_form
        args['register_form'] = register_form
    else:
        register_form = RegistrationForm()
        args['register_form'] = register_form

    return render(request, 'register.html', args)
Esempio n. 7
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password1']

            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt+username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            user = User.objects.create_user(username, email, password)
            user.is_active = False
            user.save()

            user_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
            user_profile.save()
    
            email_subject = "PartyMaker EMail Bestätigung"
            email_text = "Hallo %s,\n du hast dich bei Party Maker regierstriert. Klicke auf den folgenden\
                Link um deinen Account zu aktivieren.\n http://localhost:8000/validate/%s\n mfG das PartyMaker Team" % (
                    username, activation_key)
            email_address=settings.REGISTRATION_EMAIL_ADDRESS
            send_mail(email_subject, email_text, email_address, [email])
            return HttpResponseRedirect('thanks')
    else: 
         form = RegistrationForm()
    return render_to_response('register.xhtml', {'form':form},  context_instance=RequestContext(request)) 
Esempio n. 8
0
 def test_UserForm_invalid(self):
     form = RegistrationForm(
         data={
             'name': 'vaibhav',
             'email': '[email protected]',
             'branch': 'cse',
             'year': 'first',
             'github_url': 'test'
         })
     self.assertFalse(form.is_valid())
Esempio n. 9
0
 def test_UserForm_valid(self):
     form = RegistrationForm(
         data={
             'name': 'vaibhav',
             'email': '*****@*****.**',
             'branch': 'cse',
             'year': 2014,
             'github_url': 'https://github.com/vaibhavsingh97/'
         })
     self.assertTrue(form.is_valid())
Esempio n. 10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username = form.username.data, email = form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created. Now you are able to log in!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Login', form = form)
Esempio n. 11
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Registration successful.')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 12
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = \
            bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pwd,
                    role=form.role.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!', 'check')
        return redirect(url_for('login'))
    return render_template('register.html', form=form, title='Register')
Esempio n. 13
0
def register():
    form = RegistrationForm()
    
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        print("'" + form.username.data + "' has created a accont")
        
        return redirect(url_for("login"))
    
    return render_template("register.html", title="Register", form=form)
Esempio n. 14
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=hashed_pwd)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form)
Esempio n. 15
0
def registration(request, template_name='main/registration.html'):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            hero = Hero(login=form.cleaned_data['login'],
                        password=form.cleaned_data['password1'],
                        email=form.cleaned_data['email'],
                        sex=form.cleaned_data['sex'])
            hero.save()
            request.session['hero_id'] = hero.id
            return HttpResponseRedirect(reverse('hero'))
    else:
        form = RegistrationForm()

    variables = RequestContext(request, {'form': form})

    return render_to_response(template_name, variables)
Esempio n. 16
0
def registration(request, template_name='main/registration.html'):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            hero = Hero(login=form.cleaned_data['login'],
                        password=form.cleaned_data['password1'],
                        email=form.cleaned_data['email'],
                        sex = form.cleaned_data['sex'])
            hero.save()
            request.session['hero_id'] = hero.id
            return HttpResponseRedirect(reverse('hero'))
    else:
        form = RegistrationForm()

    variables = RequestContext(request, {'form': form})

    return render_to_response(template_name, variables)
Esempio n. 17
0
def first():
    db.create_all()
    form = RegistrationForm()
    if form.validate_on_submit():
        print('true')
        pett = Pet(kind=form.kind.data,
                   nickname=form.nickname.data,
                   age=form.age.data)
        db.session.add(pett)
        db.session.commit()
        # print(form.kind.data)
        # print(form.nickname.data)
        # print(form.age.data)
        print(db.session.query(Pet).count())
        flash(u'Питомец {} записан!'.format(form.nickname.data))
        return redirect(url_for('second'))
    print(db.session.query(Pet).count())
    return render_template('first.html', form=form)
Esempio n. 18
0
def register():
    '''
    注册,并发送激活邮件。
    即使通过配置程序已经可以在末尾自动提交数据库变化,这里也要添加db.session.commit(),因为后续确定令牌要用到id。
    '''
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, name=form.name.data, password=form.password.data, confirmed=1, image='img/default_avatar.jpg')
        if User.query.filter_by(email=form.email.data).first():
            flash('该邮箱已注册')
        else:
            db.session.add(user)
            db.session.commit()
            # token = user.generate_confirmation_token()
            # send_email(user.email, '激活邮箱', 'email/confirm', user=user, token=token)
            # flash('一封激活邮件已发往您的注册邮箱,请尽快前往确认。')
            return redirect(url_for('main.signin'))
    return render_template('register.html', form=form)
Esempio n. 19
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password,
                    nombreCompleto=form.nombreCompleto.data,
                    numTelefono=form.numTelefono.data,
                    edad=form.edad.data,
                    residencia=form.residencia.data,
                    empresa=form.empresa.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 20
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/qwer')
    else:
        form = RegistrationForm()
        arg = {'form': form}
        return render(request, 'main/register.html', arg)
Esempio n. 21
0
def register():
    if current_user.is_authenticated:
        flash("Already registered", "success")
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(
            username=form.username.data,
            email=form.email.data,
            password=hashed_password,
            category=form.category.data,
            company=form.company.data,
            position=form.position.data,
        )
        db.session.add(user)
        db.session.commit()
        flash(f"Your account has been created you can now login!", "success")
        return redirect(url_for("login"))
    return render_template("register.html", form=form)
Esempio n. 22
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    try:
        if form.validate_on_submit():

            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(name=form.name.data,
                        password=hashed_password,
                        api_code=form.api_code.data)  #add new user, 要符合form
            db.session.add(user)  #寫入資料庫
            db.session.commit()

            flash('Your account has been created! You are now able to log in',
                  'success')
            return redirect(url_for('main.login'))
    except:
        flash('Your account name already used!', 'warning')
    return render_template('register.html', title='Register', form=form)
Esempio n. 23
0
def analyzer_signup(request):
    """
	Sign up for an assistant account.
	"""

    if request.user.is_authenticated():
        return redirect('internal:profile')
    if request.method == 'POST':
        post = request.POST.copy()
        request.POST = post

        form = RegistrationForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            password = cd['password1']
            user = form.save()
            g, created = Group.objects.get_or_create(name='assistant')
            g.user_set.add(user)
            g.save()
            user = auth.authenticate(username=user.email, password=password)
            auth.login(request, user)
            return redirect('internal:profile')
        return render(request, 'analyzer_signup.html', {'form': form})
    else:
        form = RegistrationForm()
        return render(request, 'analyzer_signup.html', {'form': form})
Esempio n. 24
0
def register(request):
    """Register and create a user if a valid form is submitted"""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            return redirect('login')
    else:
        form = RegistrationForm()
    return render(request, 'main/register.html', {'form': form})
Esempio n. 25
0
 def post(self, request):
     form = RegistrationForm(request.POST)
     if not form.is_valid():
         return render(request, 'register.html', {"form": form})
     email = form.cleaned_data['email']
     first_name = form.cleaned_data['name']
     last_name = form.cleaned_data['surname']
     password = form.cleaned_data['password']
     password_2 = form.cleaned_data['password2']
     if password != password_2:
         messages.add_message(
             request, messages.WARNING,
             'Błędnie powtórzone hasło. Spróbuj jeszcze raz.')
         return render(request, 'register.html', {"form": form})
     if User.objects.filter(email=email).exists():
         messages.add_message(request, messages.WARNING,
                              'Profil o podanym emailu już istnieje.')
         return render(request, 'register.html', {"form": form})
     User.objects.create_user(username=email,
                              email=email,
                              password=password,
                              first_name=first_name,
                              last_name=last_name)
     return redirect('login')
Esempio n. 26
0
def User_Registration(request):
    if request.user.is_authenticated():
            return HttpResponseRedirect('/profile/')
    if request.method == 'POST':
            form = RegistrationForm(request.POST)
            if form.is_valid():
                    print "Formulario Valido"
                    user = User.objects.create_user(username=form.cleaned_data['username'], email=form.cleaned_data['email'], password=form.cleaned_data['password'])
                    user.save()
#                    users = user.get.profile()
#                    users.name = form.cleaned_data['name']
#                    users.birthday = form.cleaned_data['birthday']
#                    users.save()
#                    users = UserProfile(user=user, birthday=form.cleaned_data['birthday'])
#                   users.save()
                    return redirect('LoginRequest')
            else:
                print "Formulario Invalido"
                return render_to_response('RegisterUser.html', {'form': form}, context_instance=RequestContext(request))
    else:
            ''' user is not submitting the form, show them a blank registration form '''
            form = RegistrationForm()
            context = {'form': form}
            return render_to_response('RegisterUser.html', context, context_instance=RequestContext(request))
Esempio n. 27
0
def registration(request):
    edit_form = RegistrationForm()
    if request.method == 'POST':
        edit_form = RegistrationForm(data=request.POST)
        if edit_form.is_valid():
            user = edit_form.save(commit=False)
            user.username = str(uuid.uuid4().int)[:10]
            user.save()
            return redirect('login')

    return render(request, 'main/registration.html', {'edit_form': edit_form})
Esempio n. 28
0
    def post(self, request):
        is_sms = bool(request.POST.get('action') == 'send_sms')
        status = False
        form = SmsForm(request.POST) if is_sms else RegistrationForm(
            request.POST)
        if form.is_valid():
            phone = form.cleaned_data['phone']
            if Client.objects.filter(phone=phone):
                messages.error(
                    request,
                    'Пользователь с данным номером телефона уже существует')
            elif is_sms:
                sms_code = str(random.randrange(100000, 999999))
                try:
                    sms_code_object = SmsCode.objects.get(phone=phone)
                except SmsCode.DoesNotExist:
                    sms_code_object = SmsCode.objects.create(phone=phone)
                sms_code_object.sms_code = sms_code
                sms_code_object.save()
                params = {
                    'api_id': 'f567a71e-f7b2-c134-0da6-4c6bbd49602b',
                    'to': phone,
                    'msg': 'code: ' + sms_code,
                    'json': 1
                }
                content = requests.post('https://sms.ru/sms/send/',
                                        params=params).json()
                if content['status'] == 'OK':
                    status = True
                    messages.success(request, 'Код успешно отправлен в sms')
                else:
                    messages.error(request, 'Не удалось отправить sms')
            else:
                password = form.cleaned_data['password']
                sms_code = str(form.cleaned_data['sms_code'])

                if not sms_code_is_valid(sms_code, phone):
                    messages.error(request, 'Введен не правильный код')
                else:
                    user = User.objects.create_user(username=phone,
                                                    password=password)
                    Client.objects.create(phone=phone, user=user)
                    login(request, user)
                    messages.success(request, 'Регистрация успешно завершена')
                    status = True
        return form_response(request, form, status, 'home')
Esempio n. 29
0
def signup(request):
    """ User signup page """
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']
            if User.objects.filter(username=username):
                form = RegistrationForm()
                return render(request, 'signup.html', {'form':form})
            else:
                user = User.objects.create_user(username, email, password)
                user.save()
                user = authenticate(username=username, password=password)
                auth.login(request, user)
                return HttpResponseRedirect('profile')
    else:
        form = RegistrationForm()
    return render(request, 'signup.html', {'form':form})
Esempio n. 30
0
def index_page(request):
    was_saved = False
    show_message = u''
    if request.method == 'POST':
        if 'new_register' in request.POST:
            form = RegistrationForm()
        else:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                form.save()
                was_saved = True
                show_message = form.message
                form = RegistrationForm()
    else:
        form = RegistrationForm()
    ctx = {
        'show_message': show_message,
        'was_saved': was_saved,
        'form': form
    }
    return render(request, 'index.html', ctx)
Esempio n. 31
0
def register(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = RegistrationForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            post = form.save(commit=False)
            post.save()
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            messages.success(request, 'You successfully registered.')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = RegistrationForm()

    return render(request, 'register.html', {'form': form})
Esempio n. 32
0
 def test_registaration_in_valid(self):
     request_form = RegistrationForm()
     self.assertFalse(request_form.is_valid())
Esempio n. 33
0
def register():
	form = RegistrationForm()
	if form.validate_on_submit():
		flash(f"Account created for {form.name.data}!", 'success')
		return redirect(url_for('home'))
	return render_template('register.html', form=form)
Esempio n. 34
0
    def get(self, request):
        if request.user.id is not None:
            return redirect('main')

        return render(request, 'register.html', {"form": RegistrationForm()})
Esempio n. 35
0
def index_page(request):
    was_saved = False
    show_message = u''
    if request.method == 'POST':
        if 'new_register' in request.POST:
            form = RegistrationForm()
        else:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                form.save()
                was_saved = True
                show_message = form.message
                form = RegistrationForm()
    else:
        form = RegistrationForm()
    ctx = {'show_message': show_message, 'was_saved': was_saved, 'form': form}
    return render(request, 'index.html', ctx)