def createaccount(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('profile'))
    if request.method == 'POST':
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            retype_password = form.cleaned_data.get('retype_password')
            if len(email)>30:
                username = email[0:30]
            else:
                username = email
            user = User.objects.create_user(username, email, password)
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.save()
            applicant = Applicant(user = user, role = 1)
            applicant.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            application_created(user.id)
            return HttpResponseRedirect(reverse('index'))
    else:
        form = CreateAccountForm()
    return render(request, 'create_account.html', {'form':form})
Beispiel #2
0
def createAccount():
    if current_user.is_authenticated:
        flash('Для регистрации нового аккаунта выйдите из существующего')
        return redirect(url_for('account'))
    form = CreateAccountForm()
    if form.validate_on_submit():
        cursor.execute('select * from account where login = %s;',
                       (form.login.data, ))
        user = cursor.fetchone()
        if user:
            flash('Учетная запись с таким логином уже существует!')
            return redirect(url_for('createAccount'))
        if form.passwordOne.data == form.passwordTwo.data:
            cursor.execute(
                'insert into account (login, passwordHash, idTypeAccountOne, idTypeAccountTwo, idFirm) values (%s, %s, 1, 1, 1);',
                (
                    form.login.data,
                    generate_password_hash(form.passwordOne.data),
                ))
            conn.commit()
            cursor.execute('select id from account where login = %s;',
                           (form.login.data, ))
            user = cursor.fetchone()
            login_user(load_user(user[0]), remember=0)
            flash('Учетная запись создана успешно. Заполните данные профиля.')
            return redirect(url_for('fillAccount'))
        else:
            flash('Пароли не совпадают.')
            return redirect(url_for('createAccount'))
    return render_template('createAccount.html',
                           title='Создание аккаунта',
                           form=form)
Beispiel #3
0
def create_account(request):
	if request.method == 'POST':
		form = CreateAccountForm(request.POST)
		if form.is_valid():
			new_user = User.objects.create_user(username = request.POST['username'], password = request.POST['password'], email = request.POST['email'])
			new_user.save()
			username = request.POST['username']
			password = request.POST['email']
			user = authenticate(username=username, password=password)
			if user is not None:
				login(request, user)
			new_basicinfo = BasicInfo(user = new_user, over18 = request.session['over18'], birth_month=request.session['birth_month'], birth_day=request.session['birth_day'], birth_year=request.session['birth_year'], city=request.session['city'], state=request.session['state'], country=request.session['country'], zipcode=request.session['zipcode'])
			if request.session['birth_day'] <10:
				birth_day = "0"+str(request.session['birth_day'])
			else:
				birth_day = str(request.session['birth_day'])
			if request.session['birth_month'] <10:
				birth_month = "0"+str(request.session['birth_month'])
			else:
				birth_month = str(request.session['birth_month'])
			birth_year = str(request.session['birth_year'])
			new_basicinfo.birth_date_full = birth_year+"-"+birth_month+"-"+birth_day+" 00:00:00"
			new_basicinfo.save()
			new_identities = Identities(user= new_user, gender=request.session['gender'], orientation=request.session['orientation'], outness_gender=request.session['outness_gender'], outness_orientation=request.session['outness_orientation'], relationship_status=request.session['relationship_status'], ethnicity=request.session['ethnicity'])
			new_identities.save()
			new_lookingfor=LookingFor(user = new_user, lookingfor_gender=request.session['lookingfor_gender'], lookingfor_orientation=request.session['lookingfor_orientation'], age_lower=request.session['age_lower'], age_upper=request.session['age_upper'], within_range_of_zip=request.session['within_range_of_zip'], near_zip=request.session['near_zip'])
			new_lookingfor.save()
			return HttpResponseRedirect('../index')
	else:
		form = CreateAccountForm()
	return render(request, 'create_account.html', {'form': form})
def create_user():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = CreateAccountForm()
    if form.validate_on_submit():
        new_user = form.username.data
        if User.query.filter_by(username=new_user).first() is not None:
            flash('User Already Exists')
        else:
            flash("New User {} Created!".format(form.username.data))
            country = form.country.data
            country = string.capwords(country)
            if Country.query.filter_by(name=form.country.data).first() is not None:
                c =Country.query.filter_by(name=form.country.data).first()
            else:
                c = Country(name=form.country.data)
                db.session.add(c)
                db.session.commit()
            u1 = User(username=form.username.data, email=form.email.data, countryID=c.id)
            u1.set_password(form.password.data)
            db.session.add(u1)
            db.session.commit()
        return redirect('/login')

    return render_template('create_user.html', title="Create User", form=form)
Beispiel #5
0
def createAccount():
    accountForm = CreateAccountForm()
    if accountForm.validate_on_submit():
        flash('New Account requested for user {}'.format(
            accountForm.firstName.data))
        return redirect(url_for('index'))
    return render_template('createAccount.html',
                           title='Create Account',
                           form=accountForm)
Beispiel #6
0
def create_account():
    form = CreateAccountForm()
    if form.validate_on_submit():
        flash(
            f"New account requested for user {form.username.data}, email={form.email.data}"
        )
        return redirect(url_for("login"))
    return render_template("create_account.html",
                           title="Create Account",
                           form=form)
Beispiel #7
0
 def test_account_creation_form(self):
     form = CreateAccountForm({
         "username": '******',
         "email": "*****@*****.**",
         "password1": "secret",
         "password2": "secret",
     })
     self.assertTrue(form.is_valid())
     form.save()
     user = get_user_model().objects.get(username='******')
     self.assertEqual(user.username, 'test')
Beispiel #8
0
def newuser():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = CreateAccountForm()
    if form.validate_on_submit():
        user = User()
        user.username = form.username.data
        user.set_password(form.password.data)
        user.discord_name = form.discord_name.data
        user.pronunciation = form.pronunciation.data
        user.pronouns = form.pronouns.data
        user.interesting_facts = form.about.data
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=False)
        return redirect(url_for("index"))
    return render_template("create_account.html", form=form)
Beispiel #9
0
    def test_clean_password2(self):
        form = CreateAccountForm({
            "username": '******',
            "email": "*****@*****.**",
            "password1": "secret",
            "password2": "secret2",
        })

        response = self.client.post(reverse("create-account"), {
            "username": '******',
            "email": "*****@*****.**",
            "password1": "secret",
            "password2": "secret2",
        })
        self.assertContains(response, "The two password fields didn&#39;t match.")

        user = get_user_model().objects.filter(username='******')
        self.assertFalse(user)
Beispiel #10
0
def create_account():
    form = CreateAccountForm()
    if form.validate_on_submit():
        flash("Form successfully submitted", "success")
        return redirect(url_for("index"))
    return render_template("create_account.html", form=form)