Exemplo n.º 1
0
def Register():
    form = forms.RegisterForm()
    if form.validate_on_submit():
        passwordBcrypt = bcrypt.generate_password_hash(form.password.data)
        emailUnique = User.query.filter(User.email == form.email.data).all()
        usernameUnique = (User.query.filter(
            User.username == form.username.data).all())
        if usernameUnique:
            flash('Username already Existing', 'error')
        elif emailUnique:
            flash('Email already Existing', 'error')
        else:
            newUser = User(username=form.username.data,
                           password=passwordBcrypt.decode('utf-8'),
                           firstName=form.firstName.data,
                           lastName=form.lastName.data,
                           email=form.email.data,
                           role=form.role.data)
            db.session.add(newUser)
            if form.role.data == "AD":
                role = "Admin"
            elif form.role.data == "RO":
                role = "Reservation Officer"
            else:
                role = "Financial Officer"
            event = (form.username.data + ' registered as ' + role)
            newLogTrail = LogTrail(event=event)
            db.session.add(newLogTrail)
            db.session.commit()
            return redirect(url_for('main.LogIn'))
    return render_template('employee/register.html', form=form)
Exemplo n.º 2
0
async def register():

    # set up our register form
    form = forms.RegisterForm()

    # if form was submitted and validated, then:
    if form.validate_on_submit():

        # connect to db
        userDB = mongo.cx["userDB"]
        userCollection = userDB["userCollection"]

        # if username was found, user already exists.
        # can't register, flash message,
        # redirect back here again
        if userCollection.find_one({ "username" : form.username.data }) != None :
            await flash('Username already exists')
            return redirect(url_for('register'))

        # otherwise, it's valid, we can register
        # store userinfo in db
        userCollection.insert_one(
            { "username" : form.username.data, "password" : form.password.data, 
                "username-Piazza" : "", "password-Piazza" : "", "data-Piazza" : "",
                "username-Gradescope" : "", "password-Gradescope" : "", "data-Gradescope" : "",
                "username-Blackboard" : "", "password-Blackboard" : "", "data-Blackboard" : "",})

        # flash that you are registered
        await flash("You are registered")
        # redirect to login page
        return redirect(url_for('login'))
    
    # render register page
    return await render_template('register.html', title='Register', form=form)
Exemplo n.º 3
0
def register():
    if current_user.is_authenticated:
        return redirect("/")

    register_form = af.RegisterForm()

    # Check that form is valid.
    if register_form.validate_on_submit():

        # Get Username given in form
        username = register_form.username.data

        # Look for the user in the existing users.
        if am.User.query.filter_by(username=username).first():
            flash("Username already used", category="danger")
            return redirect("/register")

        # Create user to add in db
        new_user = am.User(username=username,
                           first_name=register_form.first_name.data,
                           last_name=register_form.last_name.data,
                           dob=register_form.dob.data,
                           status=True,
                           group=2)
        new_user.set_password(register_form.password.data)

        # Add user in database
        db.session.add(new_user)
        db.session.commit()

        flash("Account successfully created", category="success")
        return redirect("/login")

    else:
        return render_template("register.html", form=register_form)
Exemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        return redirect("/")
    
    register_form = af.RegisterForm()

    # Check that form is valid.
    if register_form.validate_on_submit():
        
        # Generate only once the list of users
        userList = users.keys()

        # Get Username given in form
        username = register_form.username.data

        # Look for the user in the existing users.
        user_found = au.find_user(userList, username)

        if user_found:
            flash("Username already used", category="danger")
            return redirect("/register")
        
        au.add_user(users, username, register_form.first_name.data, register_form.last_name.data, register_form.dob.data, register_form.password.data)
        flash("Account successfully created", category="success")
        return redirect("/login")

    else:
        return render_template("register.html", form=register_form)
Exemplo n.º 5
0
def register():
    form = forms.RegisterForm()
    if form.validate_on_submit():
        admin_access = False
        if os.environ.get('ADMIN'):
            if form.email.data == os.environ.get('ADMIN'):
                admin_access = True
        if admin_access:
            models.User.create_user(
                username=form.username.data,
                email=form.email.data,
                password=form.password.data,
                user_level="walrus"
            )
            user = models.User.get(models.User.email == form.email.data)
            flash(f"Registered Admin { form.email.data }", 'success')
            login_user(user)
        else:
            models.User.create_user(
                username=form.username.data,
                email=form.email.data,
                password=form.password.data,
                user_level="user"
            )
            user = models.User.get(models.User.email == form.email.data)
            flash(f"Registered { form.email.data }", 'success')
            login_user(user)
        return redirect(url_for('index'))
    return render_template('register.html', form=form)
Exemplo n.º 6
0
def register(request):
    # For now, allow only one app to be registered.
    if app_models.TwitterApp.objects.exists():
        messages.info(request,
                      _('You can only connect one Twitter app right now.'))
        return redirect('dashboard')
    if request.method == 'POST':
        register_form = app_forms.RegisterForm(request.POST)
        if register_form.is_valid():
            register_form.save()
            messages.success(request,
                             _('Successfully connected to Twitter app.'))
            return redirect('dashboard')
    else:
        register_form = app_forms.RegisterForm()
    return render(request,
                  'app/register.html',
                  context={'register_form': register_form})
Exemplo n.º 7
0
def register():
    form = forms.RegisterForm()
    if form.validate_on_submit():
        user = models.User(username=form.username.data,
                           password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("Registration complete", "success")
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Exemplo n.º 8
0
def register():
    form = forms.RegisterForm()
    if form.validate_on_submit():
        flash('You are registered.', 'success')
        models.User.create_user(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data)
        return redirect(url_for('index'))
    return render_template('public/register.html', form=form)
Exemplo n.º 9
0
def register():
    if current_user.is_authenticated:
        flash("You've been logged out.", "success")
        logout_user()
    form = forms.RegisterForm()
    if form.validate_on_submit():
        user = models.User.create_user(username=form.username.data,
                                       password=form.password.data)
        login_user(user)
        return redirect(url_for('index'))
    return render_template('register.html', form=form)
Exemplo n.º 10
0
def register():
    return 'disabled'
    form = forms.RegisterForm()

    error = None
    if form.validate_on_submit():
        res = current_app.database.register_new_account(form.data)
        if res == True:
            return redirect(url_for('user_pages.login'))
        else:
            error = res

    return render_template('registration.html', form=form, error=error)
Exemplo n.º 11
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = forms.RegisterForm()
    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()
        upath = app.config['UPLOAD_FOLDER_ROOT'] + user.username
        os.mkdir(upath)
        flash('Registration complete! Welcome to Wirehound.')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 12
0
def register():
    form = forms.RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        find = models.User.query.filter_by(username=form.username.data).first()
        if find is not None:
            flash("The username is not valid.")
            return redirect('register')
        user = models.User(username=form.username.data,
                           password=hashlib.sha1(
                               form.password.data.encode('utf-8')).hexdigest())
        db.session.add(user)
        db.session.commit()
        flash("Register Success.")
        return redirect('login')
    return render_template('register.html', form=form)
Exemplo n.º 13
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = forms.RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    user_role=form.user_role.data,
                    Region=form.Region.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Successfully Registered', category="success")
        print(form.password.data)
        print(form.user_role.data)
        print(form.Region.data)
        return redirect(url_for('login'))
    return render_template('signuppage.html', form=form, title='Register')
Exemplo n.º 14
0
def register():
    form = forms.RegisterForm(request.form)
    if request.method == "POST" and form.validate():
        db.create_all()
        find = models.User.query.filter_by(username=form.username.data).first()
        if (find):
            flash("该用户名已经被注册")
            return redirect('register')
        user = models.User(username=form.username.data,
                           password=hashlib.sha1(
                               form.password.data.encode('gbk')).hexdigest())
        file = models.File(virtualpath='/', uploader=user)
        db.session.add(user)
        db.session.commit()
        db.session.add(file)
        db.session.commit()
        flash("注册成功")
        return redirect('login')
    return render_template('register.html', form=form)
Exemplo n.º 15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = forms.RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    user_role=form.user_role.data,
                    Region=form.Region.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Successfully Registered', category="success")
        msg = Message('Welcome to CELIS',
                      sender="*****@*****.**",
                      recipients=[user.email])
        msg.body = "Hey There, We are happy that you have decided to join our community, We look forward to working with you. If you have any issues do notify us in our contact us section"
        Thread(target=send_async_email, args=(app, msg)).start()
        print(form.password.data)
        print(form.user_role.data)
        print(form.Region.data)
        return redirect(url_for('login'))
    return render_template('signuppage.html', form=form, title='Register')