Ejemplo n.º 1
0
def register():
    """ Register new user.
        user verification using Falsk WTForms, validate on submit """
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = Registration()
    if form.validate_on_submit():

        pw_hash = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(nickname=form.nickname.data,
                    email=form.email.data,
                    phone_number=form.phone_number.data,
                    password=pw_hash,
                    zipcode=form.zipcode.data,
                    intro=form.intro.data)

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

        flash(f'Account created for {form.nickname.data}! Please sign in.',
              'success')
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 2
0
def register():
    form = Registration()
    if session.get('user_id', False):
        return redirect('/account/')
    if request.method == 'POST':
        if form.validate_on_submit():
            mail = form.mail.data
            password = form.password.data
            password_confirm = form.password_confirm.data
            admin_code = form.admin_code.data
            user = db.session.query(User).filter(User.mail == mail).first()
            if user:
                err = 'Такой пользователь уже существует'
                return render_template('register.html', form=form, err=err)
            else:
                if admin_code == str(ADMIN_ACCESS):
                    is_admin = True
                else:
                    is_admin = False
                session['user_confirm_registration'] = {
                    'mail': mail,
                    'password': password,
                    'is_admin': is_admin
                }
                return redirect('/register_confirm/')
    return render_template('register.html', form=form)
Ejemplo n.º 3
0
def register():
    form = Registration()
    if form.validate_on_submit():
        print form.username.data
        #if username/email is already used
        if Acc.query.filter_by(username=form.username.data).first():
            flash('Username already exists. Try a different username.',
                  'danger')
            return redirect(url_for('register'))
        if Acc.query.filter_by(email=form.email.data).first():
            flash('Email already used. Use a different email address.',
                  'danger')
            return redirect(url_for('register'))
        #if user,email does not exist yet, and passwords match, register.
        newacc = Acc(username=form.username.data,
                     password=form.password.data,
                     email=form.email.data)
        db.session.add(newacc)
        db.session.commit()
        #user is an account. so create account first before assigning user.
        user = User(Acc.get_id(newacc), form.fname.data, form.lname.data, '')
        db.session.add(user)
        db.session.commit()
        flash('Account created for {name}!'.format(name=form.username.data),
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Ejemplo n.º 4
0
def registration():
    form = Registration()
    if form.validate_on_submit():
        flash('Account successfully created')
        gdb1 = GraphDatabase.driver(bolt_url,
                                    auth=basic_auth(usr_nm_db, pswrd_db))
        gdb = gdb1.session()

        query = '''CREATE(:users{username:'******', email:'%s', password:'******'})''' % (
            form.username.data, form.email.data, form.password.data)
        gdb.run(query)
        if (form.Animation.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Animation' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())
        if (form.Adventure.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Adventure' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Comedy.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Comedy' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Children.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Children' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Action.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Action' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Crime.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Crime' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Romance.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Romance' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())

        if (form.Drama.data == True):
            query = '''MATCH (a:users),(g:Genre) where a.username= '******' AND g.name='Drama' CREATE (a)-[:likes]->(g)
            return g.name''' % (form.username.data)
            result = gdb.run(query)
            print(result.values())
        print(form.username.data)
        return redirect(url_for('login'))
    return render_template('registration.html', form=form)
Ejemplo n.º 5
0
def changepass():
    user = User.query.filter_by(id=current_user.id).first()
    form = Registration()
    if form.validate_on_submit():
            user.password = form.password.data
            db.session.commit()
            flash('Your account has been updated!','success')
    return render_template('editprofile.html', form=form, user=user)
Ejemplo n.º 6
0
def register():
    form = Registration()
    if check_referrer() and form.validate_on_submit():
        username, password, phone = form.username.data, form.password.data, form.phone.data
        return register_with_user_info(username, password, phone)
    response = make_response(render_template('register.html', form=form))
    response = headers(response)
    return response
Ejemplo n.º 7
0
def singup():
    register_form = Registration()
    if register_form.validate_on_submit():
        email = register_form.mail.data
        name = register_form.nickname.data
        password = register_form.password.data
        existing_user = Users.query.filter_by(mail=email).first()
        if existing_user:
            abort(400)
        user = Users(name=name, mail=email)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('homepage'))
    return render_template('singup.html', form=register_form)
Ejemplo n.º 8
0
def signup():
    form = Registration()
    if form.validate_on_submit():
        print('Success')
        user = User(name=form.name.data,
                    email=form.email.data,
                    phone=form.phone.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=True)
        print(current_user)
        flash(f'' + user.name + ', your account has been created ', 'success')
        return redirect(url_for('index'))
    else:
        print('yawa')
    return render_template('signup.html', form=form)
Ejemplo n.º 9
0
def registration():
    register_form = Registration()
    if register_form.validate_on_submit():
        email = register_form.email.data
        name = register_form.username.data
        password = register_form.password.data
        existing_user = Users.query.filter_by(email=email).first()
        if existing_user:
            abort(400)
        user = Users(username=name, email=email, password=password)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('main_page'))
    return render_template('registration.html',
                           form=register_form,
                           title='Registration')
Ejemplo n.º 10
0
def register():
    form = Registration()
    if form.validate_on_submit():
        if User.query.filter_by(email=request.form['email']).first():
            flash("The email address you have provided already exists in the Bibliophile database. Please login.")
            return redirect(url_for('login'))
        else:
            new_user = User(
            name=form.name.data,
            email=form.email.data,
            password=generate_password_hash(request.form["password"], method='pbkdf2:sha256', salt_length=8)
            )
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user)
            return redirect(url_for('home'))
    return render_template("register.html", form=form, logged_in=current_user.is_authenticated)
Ejemplo n.º 11
0
def regacc():
    if conf.reg_enabled == "0":
        flash("Registration is closed", "warning")
        return redirect(url_for("login"))
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = Registration()
    if form.validate_on_submit():
        user = User(name=form.name.data, password=form.password.data,
                    admin=False, historynum=0, searchapi="lastfm", search_num=0)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=True)
        logging.info("New user: %s registered" % user.name)
        flash("Successfully registered, start searching for albums!", 'success')
        return redirect(url_for("index"))
    return render_template("reg.html", form=form)
Ejemplo n.º 12
0
def main():
    global port
    port += 1
    error = None
    form = Registration(csrf_enabled=False)
    if request.method == 'POST' and form.validate():
	try:
    	    subscriber = Subscriber(request.form['first_name'],
                                    request.form['last_name'],
                                    request.form['email'],
                                    port)
    	    db.session.add(subscriber)
    	    db.session.commit()
    	    return redirect(url_for('server', first_name=request.form['first_name']))
        except:
            error = 'Error writing to database.'
    return render_template('registration.html', form=form, error=error)
Ejemplo n.º 13
0
def register():
    form = Registration()

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

        user = User(firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    username=form.username.data,
                    email=form.email.data,
                    password=hashed)
        db.session.add(user)
        db.session.commit()
        flash(f"Congratulations! Your account has been created successfully!",
              'success')
        return redirect(url_for('login'))
    return render_template("Register.html", title='Register', form=form)
Ejemplo n.º 14
0
def register():
    form = Registration()
    
    if form.validate_on_submit():
        existing_user = user_coll.find_one({'ID': request.form['ID']})
        
        if existing_user is None:
            hashpass = bcrypt.hashpw(request.form['password'].encode('utf-8'),bcrypt.gensalt())
            user_coll.insert({'ID': request.form['ID'], 'password': hashpass, 'name':request.form['name'] , 'email':request.form['email']})
            flash(f'Account created for {form.ID.data}!','success')
            return redirect(url_for('log'))
        
        flash(f'{form.ID.data} is Already Registered!','danger')
        return redirect(url_for('login'))
            

    
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 15
0
def main():
    with open('time_logging.log', 'a') as f:
        f.write(str(dt.datetime.now()) + '\n')
    global port
    port += 1
    error = None
    form = Registration(csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        try:
            subscriber = Subscriber(request.form['first_name'],
                                    request.form['last_name'],
                                    request.form['email'], port)
            db.session.add(subscriber)
            db.session.commit()
            return redirect(
                url_for('server', first_name=request.form['first_name']))
        except:
            error = 'Error writing to database.'
    return render_template('registration.html', form=form, error=error)
Ejemplo n.º 16
0
def regiter():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = Registration()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        if form.image.data:
            image = save_image(form.image.data)
            user = User(username=form.username.data,
                        password=hashed_password,
                        image=image)
        else:
            user = User(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'{form.username.data} is  created susccessfully!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Ejemplo n.º 17
0
def register():
    form = Registration()
    # if request.method=='POST':
    #     email = request.form['email']
    #     password = request.form['password']
    #     confirm_password == request.form['confirm_password']
    #     if password == confirm_password:
    #         flash(f'Welcome, {form.username.data}!')
    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'Welcome, {form.username.data}! You can now log back in anytime.')
        return redirect(url_for('index'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 18
0
def register(request):
    if request.method == "POST":
        form = Registration(request.POST)
        if form.is_valid():
            try:
                user = User.objects.get(username__iexact=form.cleaned_data['username'])
            except User.DoesNotExist:
                if form.cleaned_data['password'] == form.cleaned_data['confirm_password']:
                    user = User.objects.create_user(
                    username=form.cleaned_data['username'],
                    password=form.cleaned_data['password'],
                    email=form.cleaned_data['email']
                    )
                    return HttpResponseRedirect('success/')
                else:
                    form = Registration()
                    variables = RequestContext(request, {
                        'form': form
                        })
                    return render(request,
                        'register.html',
                        variables,
                    )
            form = Registration()
            variables = RequestContext(request, {
                'form': form
                })
            return render(request,
                'register.html',
                variables,
            )
    else:
        form = Registration()
        variables = RequestContext(request, {
            'form': form
            })
        return render(request,
            'register.html',
            variables,
        )
Ejemplo n.º 19
0
def register():
    if current_user.is_authenticated:
        return redirect('/landing')
    else:
        form = Registration()
        if form.validate_on_submit():
            #if username/email is already used
            if User.query.filter_by(username=form.username.data).first():
                flash('Username already exists. Try a different username.','error')
                return redirect(url_for('register'))
            if User.query.filter_by(email=form.email.data).first():
                flash('Email already used. Use a different email address.','error')
                return redirect(url_for('register'))
            #if user,email does not exist yet, and passwords match, register.
            newacc = User(username=form.username.data, password=form.password.data, email=form.email.data, fname=form.fname.data, lname=form.lname.data, profession=None, contact=None, about=None)
            db.session.add(newacc)
            db.session.commit()
            flash('Account has been created! You have now logged in!','success')
            getuser = User.query.filter_by(username=newacc.username).first()
            login_user(getuser)
            return redirect(url_for('login'))
        return render_template('register.html', form=form)
Ejemplo n.º 20
0
def registration():
    if request.method == 'POST':
        try:
            user = user_datastore.create_user(
                email=request.form['email'], password=request.form['password'])
            role = Role.query[1]
            user_datastore.add_role_to_user(user, role)
            db.session.commit()
        except:
            print('Please try again.')
        return redirect(url_for('security.login'))
    form = Registration()
    return render_template('security/register.html', form=form)
Ejemplo n.º 21
0
def regacc():
    if conf.reg_enabled == "0":
        flash("Registration is closed", "warning")
        return redirect(url_for("login"))
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = Registration()
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    password=form.password.data,
                    admin=False,
                    historynum=0,
                    searchapi="lastfm",
                    search_num=0)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=True)
        logging.info("New user: %s registered" % user.name)
        flash("Successfully registered, start searching for albums!",
              'success')
        return redirect(url_for("index"))
    return render_template("reg.html", form=form)
Ejemplo n.º 22
0
def registration():
    form = Registration(request.form)
    if request.method == 'POST' and form.validate():
        user_name = request.form['name']
        user_password = request.form['password']
        user_email = request.form['email']

        user = Users.query.filter(Users.name == user_name,
                                  Users.password == user_password,
                                  Users.email == user_email).first()
        if user:
            flash('Failed! Such User already exist!', 'error')
        else:
            u = Users(name=user_name,
                      email=user_email,
                      password=user_password)
            db_session.add(u)
            db_session.commit()

            session['user_name'] = user_name
            flash('You are successful login!')
            return redirect(url_for('index'))

    return render_template('registration.html', form=form)
Ejemplo n.º 23
0
def user_created(sender, user, request, **kwargs):
    form = Registration(request.POST)
    data = UserProfile(user=user)
    try:
        data.picture = request.FILES['picture']
    except:
        data.picture = '/media/profile_images/blank-user.jpg'
    try:
        data.bio = form.data["bio"]
    except:
        pass
    try:
        string_date = form.data["date_of_birth"]
        string_date_formatted = string_date[6:] + string_date[
            3:5] + string_date[:2]
        d = datetime.datetime.strptime(string_date_formatted, "%Y%m%d").date()
        data.date_of_birth = d
    except:
        data.date_of_birth = None
    try:
        data.gender = form.data["gender"]
    except:
        data.gender = None
    data.save()
Ejemplo n.º 24
0
def register():
    form = Registration()
    return render_template('register.html',
                           form=form)  # raises error with title tag
Ejemplo n.º 25
0
def register():
    form = Registration()
    if form.validate_on_submit():
        flash(f'Account Created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('user_reg.html', title='Register', form=form)