Пример #1
0
def register():
    form = CreateUserForm()
    if form.validate_on_submit():

        if not User.query.filter_by(email=form.email.data).first() == None:
            flash("This email account has already been registered in our database.")
            return redirect(url_for("register"))
            
        hash_password = generate_password_hash(
                            password=form.password.data,
                            method="pbkdf2:sha256",
                            salt_length=8
                        )

        new_user = User(
            email = form.email.data,
            password = hash_password,
            name = form.name.data
        )
        
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)

        return redirect(url_for("get_all_posts"))
    return render_template("register.html", form=form)
Пример #2
0
def register():
    form = CreateUserForm()
    if form.validate_on_submit():
        if db.session.query(User).filter_by(email=form.email.data).first():
            flash("Email already exists, log in!")
            return redirect(url_for("login"))

        hashed_password = generate_password_hash(
            form.password.data,
            method='pbkdf2:sha256',
            salt_length=8
        )

        new_user = User()
        new_user.email = form.email.data
        new_user.name = form.name.data
        new_user.password = hashed_password

        db.session.add(new_user)
        db.session.commit()

        login_user(new_user)
        return redirect(url_for("get_all_posts"))

    return render_template("register.html", form=form, current_user=current_user)
Пример #3
0
def create_user():
    form = CreateUserForm()
    if form.validate_on_submit():
        if request.method == "POST":
            login = request.form['login']
            password = request.form['password']
            email = request.form['email']
            if not verify_psswd(password):
                flash('Your password is too weak!!')
                return redirect('/new_user')

            u = User.query.filter_by(login=login).first()
            if u:
                flash('Your data is not acceptable')
                return redirect('/new_user')

            user = User(login=login,
                        password=generate_password_hash(password,
                                                        method='sha256'),
                        email=email,
                        loggings=0)
            try:
                db.session.add(user)
                db.session.commit()
                return redirect('/')
            except:
                return "Your data is bad! Try again"
    return render_template("new_user.html", form=form)
Пример #4
0
def register():
    form = CreateUserForm()

    if form.validate_on_submit():
        email = form.email.data
        user = User.query.filter_by(email=email).first()
        if user:
            flash("An account already exists for this email. Please log in instead.")
            return redirect(url_for("login"))
        else:
            encrypted_pass = generate_password_hash(
                password=form.password.data,
                method='pbkdf2:sha256',
                salt_length=8
            )
            new_user = User(
                email=form.email.data,
                name=form.name.data,
                password=encrypted_pass
            )
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user)
            return redirect(url_for('get_all_posts'))
    return render_template("register.html", form=form)
Пример #5
0
def addprofile():
    userform = CreateUserForm()
    if request.method == 'POST':
        if userform.validate_on_submit():
            firstname  = userform.firstname.data
            lastname   = userform.lastname.data
            email      = userform.email.data
            biography  = userform.biography.data
            location   = userform.location.data
            sex        = userform.gender.data
            
            created_on = format_date_joined()
            
            photo      = userform.photo.data
            filename   = photo.filename
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename)) 
            
            newUser=UserProfile(first_name=firstname,last_name=lastname,email=email,location=location,sex=sex,created_on=created_on,filename=filename,biography=biography)
            db.session.add(newUser)
            db.session.commit()
            
            flash("User Created")
            return redirect(url_for("viewprofiles"))
        else:
            flash_errors(userform)

            
    return render_template('profile.html',form=userform)
Пример #6
0
def registration():
    """show register user form on GET request and handle form submit on POST request"""
    if 'username' not in session:
        form = CreateUserForm()
        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data
            email = form.email.data
            first_name = form.first_name.data
            last_name = form.last_name.data
            new_user = User.register(username, password, email, first_name,
                                     last_name)
            db.session.add(new_user)
            try:
                db.session.commit()
            except IntegrityError:
                form.username.errors.append('Username Taken')
                return render_template('register.html', form=form)
            session['username'] = new_user.username
            flash('Welcome! Successfully created your account!', 'success')
            return redirect(f'/users/{username}')

        return render_template('register.html', form=form)

    username = session['username']
    return redirect(f'/users/{username}')
Пример #7
0
def show_user_form():
    """ Show form to create a user """
    if session.get('username'):
        return redirect(f"/users/{session.get('username')}")

    form = CreateUserForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        new_user = User.register(username, password, email, first_name,
                                 last_name)
        db.session.add(new_user)
        db.session.commit()

        session['username'] = new_user.username

        return redirect(f"/users/{username}")

    else:
        return render_template('user_form.html', form=form)
Пример #8
0
def create_user():
    user = current_user
    title = 'Create User'
    header = 'Create a User'

    form = CreateUserForm()
    if form.validate_on_submit():
        hashed_password = hashlib.sha512(form.password.data).hexdigest()
        new_user = User(nickname=form.nickname.data,
                        email=form.email.data,
                        password=hashed_password)
        if form.is_admin.data:
            new_user.role = ROLE_ADMIN

        try:
            db.session.add(new_user)
            db.session.commit()
            flash('User "' + form.nickname.data + '" created!')
            return redirect('/index')
        except IntegrityError as e:
            flash(e.message)
            return redirect('/create_user')

    return render_template('create_user.html',
                           user=user,
                           title=title,
                           header=header,
                           form=form)
Пример #9
0
def landing():
    if request.authorization:
        return redirect(url_for('.home'))
    form = CreateUserForm()
    if form.validate_on_submit():
        u = User(form.name.data, form.password.data, form.email.data)
        session.add(u)
        session.commit()
        return redirect(url_for('.home'))
    return render_template('landing.html', form=form)
Пример #10
0
def newUser():
    form = CreateUserForm()

    if form.validate_on_submit():
        if form.accountType.data != 'a' or form.accountType.data != 'p' or form.accountType.data != 's':
            db.session.add(
                User(form.email.data, form.password.data,
                     form.accountType.data))
            db.session.commit()
            app.logger.info("New User " + form.email.data + " registered")
            return redirect(url_for('dashboard'))

        return redirect(url_for('error'))

    return render_template('newUser.html', form=form)
def createuser():
	form = CreateUserForm()
	user = form.createuser.data
	createdb_choice = form.select_options.data
	if not user:
		return flask.render_template('querydetails.html',form = form)
	else:
		Query = "CREATE USER " + user + ' ' + createdb_choice + ';'
		try:
			if form.validate_on_submit():
				db.engine.execute(Query)
				flash("User Creation Successfull!")
				return flask.render_template('querydetails.html',form = form)
		except Exception:
			flash("Something Wrong With The Create User Query")
			return flask.render_template('querydetails.html',form = form)
Пример #12
0
def user_create():
    if not current_user.is_anonymous:
        redirect(url_for('index'))

    form = CreateUserForm(request.form)

    if form.validate_on_submit():

        Cliente.create(
            username=form.username.data,
            password=form.password.data
        )

        return u'Usuario: {} creado con éxito'.format(form.username.data)

    return render_template('create_user.html', form=form)
Пример #13
0
def registration_form():
    """Show and handle user registration form"""

    form = CreateUserForm()

    if form.validate_on_submit():
        current_user = User.register(form.username.data, form.password.data,
                                     form.email.data, form.first_name.data,
                                     form.last_name.data)
        db.session.add(current_user)
        db.session.commit()
        session["username"] = current_user.username
        return redirect(f'/users/{current_user.username}', code=302)

    else:
        return render_template('register_form.html', form=form)
Пример #14
0
def signup():

	form = CreateUserForm()

	if form.validate_on_submit():
		user = User(username=form.username.data,
					email=form.email.data,
					password=form.password.data)

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

		login_user(user, remember=True)

		return redirect(url_for(users.index))

	return render_template('users/signup.html', form=form)
Пример #15
0
def register():
    global is_admin
    user_form = CreateUserForm()
    if user_form.validate_on_submit():
        name = user_form.name.data
        email = user_form.email.data
        password = generate_password_hash(user_form.password.data, method='pbkdf2:sha256', salt_length=8)
        new_user = User(
            name=name,
            email=email,
            password=password
        )
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)
        if new_user.id == 1:
            is_admin = True
    return render_template("register.html", form=user_form)
Пример #16
0
def create():
    if REGISTRATION == REGISTRATION_OPEN:
        form = CreateUserForm()
        if form.validate_on_submit():
            new_user = User(username=form.username.data,
                email=form.email.data,
                password=pbkdf2_sha256.encrypt(form.password.data))
            new_user.put()
            return redirect(url_for('panel'))
            #else:
            #    flash('Invalid details. Please try again.')
            #    redirect(url_for('create'))
        return render_template('users/create.html',
            title='Create account',
            form=form)
    else:
        return render_template('users/closed.html',
            title='Registration closed.')
Пример #17
0
def user_create():
    if not current_user.is_anonymous:
        return redirect(url_for('index'))

    form = CreateUserForm(request.form)
    if form.validate_on_submit():
        try:
            user = Cliente.get(Cliente.nombre == form.username.data)
            if user:
                return render_template('create_user.html', form=form, error=u'nombre de usuario ya existente en sistema')
        except:
            Cliente.create(
                nombre=form.username.data,
                password=form.password.data,
                fechaInscripcion=datetime.now()
            )
            return render_template('create_user_success.html', username=form.username.data)

    return render_template('create_user.html', form=form)
Пример #18
0
def register():
    form = CreateUserForm()
    if form.validate_on_submit():
        if Users.query.filter_by(email=form.email.data).first():
            flash("You have already registered. Please login instead.")
            return redirect(url_for("login"))
        else:
            user_hash = generate_password_hash(form.password.data,
                                               method='pbkdf2:sha256',
                                               salt_length=8)

            new_user = Users(email=form.email.data,
                             password=user_hash,
                             name=form.name.data)
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user)
            return redirect(url_for('get_all_posts'))
    return render_template("register.html", form=form)
Пример #19
0
def user_login():
    print current_user.is_anonymous

    if not current_user.is_anonymous:
        redirect(url_for('index'))
	
    form = CreateUserForm(request.form)
    if form.validate_on_submit():
        try:
            user = Cliente.get(username = form.username.data,
                password = form.password.data)
            print dir(user)
            print type(user)
            print user.is_anonymous
            login_user(user)
            return redirect(url_for('index'))
        except:
            return u'Usuario o contraseña inválida'

    return render_template('login.html', form=form)
Пример #20
0
def register():
    users = User.query.all()
    form = CreateUserForm()
    if form.validate_on_submit():
        for user in users:
            if user.email == form.email.data:
                flash(
                    "The email you entered already exists, please enter it again"
                )
                return redirect(url_for("register"))
        new_user = User(
            email=form.email.data,
            password=generate_password_hash(form.password.data),
            name=form.name.data,
        )
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)
        return redirect(
            url_for("get_all_posts", logged_in=current_user.is_authenticated))
    return render_template("register.html", form=form)
Пример #21
0
def register():
    register_form = CreateUserForm()
    if register_form.validate_on_submit():

        if User.query.filter_by(email=register_form.email.data).first():
            # Send flash messsage
            flash("You've already signed up with that email, log in instead!")
            # Redirect to /login route.
            return redirect(url_for('login'))
        hashed_password = generate_password_hash(request.form.get('password'),
                                                 method='pbkdf2:sha256',
                                                 salt_length=8)
        new_user = User(email=request.form.get('email'),
                        name=request.form.get('name'),
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('get_all_posts'))
    return render_template("register.html",
                           form=register_form,
                           current_user=current_user)
Пример #22
0
def create_user():
    form = CreateUserForm()
    if form.validate_on_submit():
        valid = True
        users = application.config['auth_domain'].get_users()
        if (form.username.data in [user.username for user in users]):
            form.username.errors.append("Username is not unique.")
            valid = False
        if (form.email.data in [user.email for user in users]):
            valid = False
            # TODO: handle this
        if (valid):
            username = form.username.data
            email = form.email.data
            password = form.password.data
            application.config['auth_domain'].add_user(username, email,
                                                       password)
            return redirect(url_for('accounts.get_login_form'))
    else:
        return render_template("create_user.html",
                               title="Create Account",
                               form=form)
Пример #23
0
def submit_register_form():
    """Submits the user registration form."""

    form = CreateUserForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        new_user = User.register(username, password, email, 
                                 first_name, last_name)

        db.session.add(new_user)
        db.session.commit()
        session["username"] = new_user.username

        return redirect(f"/users/{new_user.username}")
    else:
        return render_template('register.html', form=form)
Пример #24
0
def create_user():
    if not g.user.is_admin():
        logger.error("%s tried to access /create-user", g.user.email, id)
        abort(403)
    form = CreateUserForm()

    if form.validate_on_submit():
        if request.form['button'] == 'Cancel':
            return form.redirect(url_for('user_list'))
        user = User(email = form.email2.data,
                    password = form.pass2.data,
                    name = form.name.data)

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

        flash("User successfully created")
        logger.info("%s was registered", user.email)
        return redirect(url_for('user_list'))

    return render_template('admin_register.html',
            title = "Create a new user",
            form = form)
Пример #25
0
def create_user():
    if not g.user.is_admin():
        logger.error("%s tried to access /create-user", g.user.email, id)
        abort(403)
    form = CreateUserForm()

    if form.validate_on_submit():
        if request.form['button'] == 'Cancel':
            return form.redirect(url_for('user_list'))
        user = User(email=form.email2.data,
                    password=form.pass2.data,
                    name=form.name.data)

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

        flash("User successfully created")
        logger.info("%s was registered", user.email)
        return redirect(url_for('user_list'))

    return render_template('admin_register.html',
                           title="Create a new user",
                           form=form)
Пример #26
0
def create_user_page():

    if not current_user.is_admin():
        return render_template('not_found_page.html'), 404

    form = CreateUserForm()

    if form.validate_on_submit():
        user_query = User.get_by_id(form.email.data)
        if user_query:
            logging.info("User already exists")
        else:
            user = User(id=form.email.data)
            user.name = form.name.data
            user.password = generate_password_hash(form.password.data)
            user.put()
            return redirect(url_for('web_app.users_page'))

    random_pass = random_password()

    return render_template('create_user_page.html',
                           nav_link='create_user_page',
                           form=form,
                           random_pass=random_pass)
Пример #27
0
def createUser():
    form = CreateUserForm()
    if form.validate_on_submit():
        flash('New user created', 'success')
        return redirect(url_for('loginOrCreate'))
    return render_template('create_user.html', title='Create User', form=form)