Exemplo n.º 1
0
def sign_up():
    form = SignUp()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        if request.form.get("email") == "*****@*****.**":
            flash("Welcome aboard! 🥘", "success")
            return redirect("/index")
        else:
            flash("Sorry, something went wrong 😿", "danger")
    return render_template("sign_up.html", title="Sign up", form=form)
Exemplo n.º 2
0
def sign_up(request):
    if request.method == 'POST':
        form = SignUp(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f"new account created : {username}")
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            student = Student()
            student.user = username
            student.save()
            return redirect("/")

        else:
            for msg in form.error_messages:
                messages.error(request, f"{msg}: {form.error_messages[msg]}")
        return render(request=request,
                      template_name='main/register.html',
                      context={"form": form})

    form = SignUp()
    return render(request=request,
                  template_name='main/register.html',
                  context={"form": form})
Exemplo n.º 3
0
def signup():
    createuser = SignUp()
    
    if request.method == "POST" and  createuser.validate_on_submit():
                fname = createuser.fname.data
                lname = createuser.lname.data
                email = createuser.email.data
                gender=createuser.gender.data
                password=createuser.password.data
                created_date=format_date_joined(datetime.datetime.now())
                 # get the last userid and then add it to one to get new userid
                db.engine.execute("insert into Users (firstname,lastname,email,gender,password) values('"+fname+"','"+lname+"','"+email+"','"+gender+"','"+password+"')")
                

                return redirect(url_for('setupprofile'))
    else:
                flash_errors(createuser)
    return render_template('signup.html',form=createuser)  
Exemplo n.º 4
0
def sign_up():
    form = SignUp()
    success, message = Sign_up(form)
    flash(message[0], message[1])
    if success:
        return redirect("home")
    return render_template('sign_up.html.j2',
                           title="Sign Up",
                           form=form,
                           info=info())
Exemplo n.º 5
0
def sign_up():
    form = SignUp()
    if form.validate_on_submit():

        user_to_create = User(email=form.email.data,
                              username=form.username.data,
                              first_name=form.firstname.data,
                              last_name=form.lastname.data,
                              password=form.password1.data)

        db.session.add(user_to_create)
        db.session.commit()
        print("Data Added to db")
        return redirect(url_for('sign_in'))

    if form.errors != {}:  # No errors from validations
        for err_msg in form.errors.values():
            flash(f'There is a error:{err_msg}', category='danger')

    return render_template("sign-up.html", form=form)
Exemplo n.º 6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('feed'))
    form = SignUp()
    if form.validate_on_submit():
        try:
            citizen = Citizen(citizen_id=form.citizen_id.data,
                              name=form.citizen_id.data,
                              score=20000,
                              profile_image=url_for(
                                  'static',
                                  filename='assets/blank_profile.png'))
            citizen.set_password(form.password.data)
            db.session.add(citizen)
            db.session.commit()
            login_user(citizen)
            return redirect(url_for('feed'))
        except Exception as e:
            flash('User already exists')
            print('There was an error creating new user.' + str(e))
    return render_template('register.html',
                           links=get_links(),
                           title='Join Arch',
                           form=form)
Exemplo n.º 7
0
def Sign_up(form: SignUp) -> list:
    if form.validate_on_submit():
        name = form.name.data
        secondname = form.secondname.data
        username = form.username.data
        password = form.password.data
        passwordRet = form.passwordRet.data
        if (not validateName(name)):
            return [0, ("Name is not correct", 'message red')]
        if (not validateName(secondname)):
            return [0, ("Secondname is not correct", 'message red')]
        if (not validateName(username)):
            return [0, ("Username is not correct", 'message red')]
        if storage.storage.getUserByName(username) != None:
            return [0, ("There is a user with this username", 'message red')]
        if password != passwordRet:
            return [0, ("Passwords don't match", 'message red')]
        user = structures.User(storage.storage.getUsersCount(), username, password, structures.UserType.Default, {}, name, secondname)
        storage.storage.saveUser(user)
        return [1, ("Signed up successfully", 'message green')]
    return [0, ("You must fill all fields with *", 'message blue')]
Exemplo n.º 8
0
def register(typeUser):
    # First Name, Last Name, Email, Password and Username are collected from the SignUp Form
    form = SignUp()

    if request.method == "POST" and form.validate_on_submit():
        mycursor = mysql.connection.cursor()
        # Collects username and email info from form
        username = form.username.data
        email = form.email.data

        # Checks if another user has this username
        mycursor.execute('SELECT * FROM user WHERE username = %s',
                         (username, ))
        existing_username = mycursor.fetchone()

        # Checks if another user has this email address
        mycursor.execute('SELECT * FROM user WHERE email = %s', (email, ))
        existing_email = mycursor.fetchone()

        # Gets last record in User Table
        mycursor.execute('SELECT * from user ORDER BY user_id DESC LIMIT 1')
        lastRec = mycursor.fetchone()
        if lastRec is None:
            lastRec = 1
        else:
            lastRec = lastRec['user_id'] + 1

        # If unique email address and username provided then log new user
        if existing_username is None and existing_email is None:
            mycursor = mysql.connection.cursor()
            sql = "INSERT INTO User (user_id, type, first_name, last_name, username, email, password) VALUES (%s, %s, %s, %s, %s, %s, %s)"
            val = (lastRec, typeUser, request.form['fname'],
                   request.form['lname'], request.form['username'],
                   request.form['email'], request.form['password'])

            mycursor.execute(sql, val)
            mysql.connection.commit()

            last = mycursor.lastrowid

            # Specialisation of Users
            if typeUser == "Regular":
                # Calls RandomFeatures  function to generate features for regular user
                randFt = randomFeatures()

                sql = "INSERT INTO Regular (user_id, sex, age, height, leadership, ethnicity, personality, education, hobby, occupation, pref_sex, pref_ethnicity) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
                val = (mycursor.lastrowid, randFt[0], randFt[1], randFt[2],
                       randFt[3], randFt[4], randFt[5], randFt[6], randFt[7],
                       randFt[8], randFt[9], randFt[10])

                mycursor.execute(sql, val)
                mysql.connection.commit()

            else:
                position = random.choice([
                    'Secretary', 'CEO', 'Treasurer', 'Vice President',
                    'Supervisor', 'Manager'
                ])

                sql = "INSERT INTO Organizer (user_id, position) VALUES (%s, %s)"
                val = (mycursor.lastrowid, position)

                mycursor.execute(sql, val)
                mysql.connection.commit()

            # Success Message Appears
            flash('Successfully registered', 'success')

            # Logs in a newly registered user
            session['logged_in'] = True
            session['id'] = last
            session['username'] = request.form['username']
            session['TYPE'] = typeUser
            session['first_name'] = request.form['fname']
            session['last_name'] = request.form['lname']

            # Redirects to Profile Page
            return redirect(
                url_for('dashboard', username=session.get('username')))

    # Flash errors in form and redirects to Register Form
    flash_errors(form)
    return render_template("signup.html", form=form)