示例#1
0
def newAccount():
    cursor.execute('select name, login, status from account where id = %s',
                   (current_user.id, ))
    user = cursor.fetchone()
    if user[2] == 0:
        flash('Отказано в доступе')
        return redirect(url_for('account'))
    form = CreateAccountForm()
    if form.validate_on_submit():
        cursor.execute('select * from account where login = %s',
                       (form.login.data, ))
        check_user = cursor.fetchone()
        if check_user:
            flash('Учетная запись с таким логином уже существует!')
            return redirect(url_for('newAccount'))
        cursor.execute(
            'insert into account (login, passwordHash, name, status) values (%s, %s, %s, %s);',
            (
                form.login.data,
                generate_password_hash(form.password.data),
                form.name.data,
                form.level.data,
            ))
        conn.commit()
        flash('Учетная запись для {} создана успешно!'.format(form.name.data))
        flash('Login: {}'.format(form.login.data))
        flash('Password: {}'.format(form.password.data))
        return redirect(url_for('account'))
    return render_template('newAccount.html',
                           title='Создание аккаунта',
                           form=form,
                           user=user)
def signup():
    #定义注册form表单
    signup_form = CreateAccountForm(request.form)
    #如果为post请求,则获取参数
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        password2 = request.form['password2']
        #判断两次密码输入是否一致
        if password != password2:
            return render_template('login/signup.html',
                                   signup_form=signup_form,
                                   msg="两次密码不一致")
        #查询用户是否存在,
        user = User.query.filter_by(username=username).first()
        #如果存在则提示错误
        if user is not None:
            return render_template('login/signup.html',
                                   signup_form=signup_form,
                                   msg="用户名已存在")
        #注册用户,提交
        user = User(username=username, password=password)
        db.session.add(user)
        db.session.commit()
        return redirect("/login")
    return render_template('login/signup.html', signup_form=signup_form)
示例#3
0
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)
示例#4
0
def createAccount():
    #URL = "https://ofe3yhbyec.execute-api.us-east-1.amazonaws.com/beta/testapicall"

    accountForm = CreateAccountForm()
    if accountForm.validate_on_submit():
        first = accountForm.firstName.data
        last = accountForm.lastName.data
        zipCode = accountForm.zipCode.data

        user = accountForm.email.data
        password = accountForm.password.data

        if accountForm.check_password(password):
            URL = "https://ofe3yhbyec.execute-api.us-east-1.amazonaws.com/beta/socdoc-create-account?username=%s&password=%s&firstname=%s&lastname=%s&zipcode=%s" % (
                user, password, first, last, zipCode)
            print(URL)
            r = requests.get(url=URL)
            print("\n")
            print(r.json())
            #print(type(r.json()))
            #flash('New Account requested for user {}'.format(accountForm.firstName.data))
            return redirect(
                url_for('createAccount_success',
                        first=first,
                        last=last,
                        user=user))

    return render_template('createAccount.html',
                           title='Create Account',
                           form=accountForm)
示例#5
0
文件: routes.py 项目: TMust98/Agency
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)
示例#6
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)
示例#7
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)
示例#8
0
def create_account():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = CreateAccountForm()
    if form.validate_on_submit():
        user = User(username=form.username.data)
        user.set_password(form.password.data)
        user.save_to_db()
        flash('Account Creation successful')
        return redirect(url_for('login'))
    return render_template('create-account.html', form=form)
示例#9
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')
示例#10
0
def login():
    """
        function to render login page
    """
    login_form = LoginForm(request.form)
    create_account_form = CreateAccountForm(request.form)

    return render_template(
        'login.html',
        login_form=login_form,
        create_account_form=create_account_form,
    )
示例#11
0
def newuser():
    form = CreateAccountForm()
    if form.validate_on_submit():
        flash(
            'Login requested for user {}, remember_me={}, e {}, p {}, cp {}, pn {}, sa {}'
            .format(form.first_name.data, form.last_name.data,
                    form.email_address.data, form.password.data,
                    form.confirm_password.data, form.phone_number.data,
                    form.security_answers.data))
        return redirect('/confirmation')
    return render_template('create_account.html',
                           title='Create Account',
                           form=form)
示例#12
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)
示例#13
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't match.")

        user = get_user_model().objects.filter(username='******')
        self.assertFalse(user)
示例#14
0
def register():
    login_form = LoginForm(request.form)
    create_account_form = CreateAccountForm(request.form)
    if 'register' in request.form:

        username = request.form['username']
        email = request.form['email']
        password = request.form['password']

        # Check usename exists
        user = User.query.filter_by(username=username).first()
        if user:
            return render_template('login-register/register.html',
                                   msg='Username already registered',
                                   success=False,
                                   form=create_account_form)

        # Check email exists
        user = User.query.filter_by(email=email).first()
        if user:
            return render_template('login-register/register.html',
                                   msg='Email already registered',
                                   success=False,
                                   form=create_account_form)

        # else we can create the user
        user = User(username=username,
                    email=email,
                    password=password,
                    idTelegram=None)
        db.session.add(user)
        db.session.commit()
        send_email("Welcome in smart hive", "Test", email)

        return render_template(
            'login-register/register.html',
            msg='User created please <a href="/login">login</a>',
            success=True,
            form=create_account_form)

    else:
        return render_template('login-register/register.html',
                               form=create_account_form)
示例#15
0
def register():
    login_form = LoginForm(request.form)
    create_account_form = CreateAccountForm(request.form)
    if 'register' in request.form:

        username = request.form['username']
        email = request.form['email']

        # Check usename exists
        # user = User.query.filter_by(username=username).first()
        # if user:
        # return render_template( 'accounts/register.html',
        # msg='Username already registered',
        # success=False,
        # form=create_account_form)

        # Check email exists
        # user = User.query.filter_by(email=email).first()
        # if user:
        # return render_template( 'accounts/register.html',
        # msg='Email already registered',
        # success=False,
        # form=create_account_form)
#
# else we can create the user
# user = User(**request.form)
# db.session.add(user)
# db.session.commit()
#
# return render_template( 'accounts/register.html',
# msg='User created please <a href="/login">login</a>',
# success=True,
# form=create_account_form)
#
# else:
    return render_template('views/accounts/register.html',
                           form=create_account_form)
示例#16
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)