예제 #1
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'main/login.html', {})

    else:
        form = RegistrationForm()

    return render(request, 'main/register.html', {'form': form})
예제 #2
0
파일: app.py 프로젝트: amanchopra95/flabber
def signup():
    title = "Registration Form"
    error = None
    form = RegistrationForm()

    if request.method == 'POST' and form.validate_on_submit():

        if users.find_one({'username': form.username.data}) is None:

            hashpw = generate_password_hash(form.password.data)
            users.insert({
                'username': form.username.data,
                'password': hashpw,
                'name': form.name.data,
                'email': form.email.data
            })

            new_user = User(form.username.data)
            login_user(new_user)

            session['logged_in'] = True
            session['username'] = form.username.data

            flash('Registration Successfull', 'success')
            return redirect(url_for("dashboard"))

        else:
            error = "Username already exists."

    return render_template("signup.html", form=form, title=title, error=error)
예제 #3
0
def signup():
    form = RegistrationForm()

    if form.validate_on_submit():
        username1 = form.username.data
        phone1 = form.phone.data
        email1 = form.email.data
        password1 = form.password.data
        company = form.companyname.data
        cur = con.cursor()
        cur.execute("SELECT * from usertable WHERE email='" + email1 + "'")
        data = cur.fetchone()
        if (data != []):
            cur.execute(
                "INSERT INTO usertable (username,email,password,phone,company) VALUES (%s,%s,%s,%s,%s)",
                (username1, email1, password1, phone1, company))
            con.commit()
            flash(f'Account succesfully created for {username1}! Just Login',
                  'success')
            return redirect(url_for('index'))
        else:
            flash(f'Given Email ID is already Used', 'danger')
            return render_template("signup.html",
                                   title='Inventory|signup',
                                   form=form)
    return render_template("signup.html", title='Inventory|signup', form=form)
예제 #4
0
def sign_up():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data
        email = form.email.data

        # Connect to sql and insert values
        cur = mysql.connection.cursor()
        check = cur.execute("SELECT * FROM usr_table WHERE usr_account = %s",
                            [email])
        if check > 0:
            flash(f'account is used', 'danger')
            return redirect(url_for('sign_up'))
        else:
            cur.execute(
                "INSERT INTO usr_table(usr_account, usr_password, usr_usrname) "
                "VALUES(%s, %s, %s)", (email, password, username))

            # commit and close connection
            mysql.connection.commit()
            cur.close()
            flash(f'account for {form.username.data} are created', 'success')
            if 'admin_log_in' in session:
                return redirect(url_for('admin'))
            return redirect(url_for('log_in'))

    return render_template("sign-up.html", form=form)
예제 #5
0
def registration():
    form = RegistrationForm()
    if form.validate_on_submit():  # Обрабатываем метод POST
        # Выполняем проверку на уникальность параметра 'Email' перед записью в базу данных.
        new_email = form.email.data  # Получаем введеный пользователем email
        email = User.query.filter_by(
            email=new_email).first()  # Делаем запрос к базе дыннх.
        # Если пользователь с таком Email нет в базе данных,регистрируем его
        if email is None:
            New_user(
                form
            )  # Данны с формы отправляем в другой модуль,для записи в db
            flash(
                'Регистрация прошла успешно.\n'
                'Пожалуйста, перейдите по ссылке, чтобы подтвердить свою регистрацию.\n'
                'Мы отправили электронное письмо на указанный почтовый адрес.')
            return redirect(url_for('main'))
        else:
            # Если пользователь с таким Email зарегистрирован в базе,тогда сообщаем об этом.
            flash(
                f'Пользователь с адресом "{new_email}" уже зарегистрирован на сайте.'
            )
            return redirect(url_for('registration'))
    else:
        return render_template('registration.html', form=form)
예제 #6
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account Created for {form.username.data}!', 'success')
        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form = form)
예제 #7
0
def teacher_update(code):
    if request.method == "POST":
        myform = RegistrationForm(studentno, request.form["username"],
                                  request.form["password"],
                                  request.form["name"],
                                  request.form["surname"])
        try:
            connection = db.connect(url)
            cursor = connection.cursor()
            print(studentno)
            statement = """UPDATE teachers SET username = \'{}\', password = \'{}\', name = \'{}\', surname = \'{}\'
            WHERE st_id = \'{}\';""".format(myform.username, myform.password,
                                            myform.name, myform.surname,
                                            studentno)
            print(statement)
            cursor.execute(statement, (myform.username, myform.password,
                                       myform.name, myform.surname))
            connection.commit()
            cursor.close()
            flash('Your account was updated successfully')
            return redirect(url_for('profile', mid=studentno))
        except db.DatabaseError:
            connection.rollback()
            flash('Unsuccessful', 'danger')
        finally:
            connection.close()
    return render_template('update.html', st=studentno)
예제 #8
0
def register():
    form = RegistrationForm()
 
    if form.validate_on_submit():
        
        #make sure an existing user doesn't already exist
        exists = False
        try:
            u = User_db.objects.get(id=(request.form['username']))
            exists = True
        except:
            print("")

        if exists:
            flash("that username already exists")
            return redirect("/register")
        

        #hash password
        hash_pw = sha256_crypt.hash(request.form['password'])

        #store data in db
        new_user = User_db(id = request.form['username'], password = hash_pw).save()

        return redirect("/login") #CHANGE
    elif request.method == "POST":
        flash("bad registration")
        return redirect("/register")                    
        
    print(form.errors)
    return render_template("register.html", form = form)
예제 #9
0
def register():

    form = RegistrationForm(request.form)
    hashed_password = generate_password_hash(form.password.data)
    user_email = request.form.get("user_email")
    username = request.form.get("username")
    password = request.form.get("password")
    confirm_password = hashed_password
    user = User.query.filter_by(user_email=user_email).first()
    if not user_email or not username:
        flash(u'fields should not be empty', 'warning')
        return redirect(url_for('register'))

    if user:
        flash(u'Email address already exists.', 'warning')
        return redirect(url_for('register'))

    new_user = User(user_email=user_email,
                    username=username,
                    password=password,
                    confirm_password=confirm_password)

    db.session.add(new_user)
    db.session.commit()
    flash(u'Your account has been created.You can now login.', 'success')
    return redirect(url_for('login'))
예제 #10
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(form.username.data, form.email.data, form.password.data)
        db_session.add(user)
        flash('Thanks for registering')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
예제 #11
0
def register():
    registrationform = RegistrationForm()
    if registrationform.validate_on_submit():
        flash(
            "Account successfully create for %s" %
            (registrationform.username.data), "success")
        return redirect(url_for('home'))
    return render_template("register.html", registrationform=registrationform)
예제 #12
0
def do_register():
    try:
        form = RegistrationForm(request.form)
        if request.method == "POST" and form.validate():
            print('validating was a success')
            username = form.username.data
            company_name = form.company_name.data
            email = form.email.data
            password = sha256_crypt.encrypt((str(form.password.data)))

            # check by username if a user is new or existent...
            user_exists = sqlsession.query(User).filter(
                User.username == username).first()
            # ... if it exists, notify the user
            if user_exists:
                error = "That username is already taken, please choose another"
                return render_template('register.html', form=form, error=error)
            # ..else, create the new user and company
            else:
                print('success, user does not exist yet')
                sqlsession.add(CompanyVN(company_name=company_name))
                the_company = sqlsession.query(CompanyVN).order_by(
                    CompanyVN.id.desc()).first()
                new_user = User(username=username,
                                company_name=company_name,
                                email=email,
                                password=password,
                                company_id=the_company.id)
                sqlsession.add(new_user)

                sqlsession.commit()
                # flash('thanks for registering')
                welcome_text = 'Hi, you created and account with us at https://interactivenarrator.science.uu.nl'

                send_email('Your account with Interactive Narrator', email,
                           welcome_text)
                session['logged_in'] = True
                session['username'] = username

                if session['username'] == 'admin':
                    return redirect(url_for('admin_dashboard'))
                else:
                    return redirect(url_for('show_dash'))

        else:
            return render_template("register.html", form=form)

    except Exception as e:
        print('an exception occured', e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
        # make sure the session is reverted if an error occured
        sqlsession.rollback()

        error = 'Sorry, we could not register you'

        return render_template('register.html', form=form, error=error)
예제 #13
0
def registrar():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        #user = User(form.username.data, form.email.data,
                   # form.password.data)
       # db_session.add(user)
        flash('Obrigado por registrar')
        return redirect(url_for('login'))
    return render_template('admin/registrar.html', form=form)
예제 #14
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('注册完成')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
예제 #15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('frontPage'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = models.User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('You are now registered!')
        return redirect(url_for('logIn'))
    return render_template('register.html', title='Register', form=form)
예제 #16
0
def register():
    if current_user.is_authenticated:
        redirect(url_for('index'))
    form = RegistrationForm()
    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()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template("register.html", title='Registration', form=form)
예제 #17
0
파일: instaapp.py 프로젝트: j-miin/insta
def create():
    form = RegistrationForm(request.form)
    new_user = User(form.username.data, form.email.data, form.password.data)
    new_user.set_password(form.password.data)
    if new_user.validation_errors == []:
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('login'))

    return render_template('register.html',
                           form=form,
                           validation_errors=new_user.validation_errors)
예제 #18
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = BookUser(username=form.username.data,
                        password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('You can now login')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
예제 #19
0
파일: user.py 프로젝트: imcj/ioa
    async def post(self):
        post = await self.request.post()
        form = RegistrationForm(post)

        if form.validate():
            try:
                user = await self.service.register(form.data)
                self.request['session']['user_id'] = user['id']
                return web.HTTPFound("/")
            except DuplicatedUser as e:
                form.username.errors.append(e)

        return {'form': form}
예제 #20
0
def reg():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data,
                                                 method='sha256')
        new_user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()

        return redirect(url_for('login'))
    return render_template('index.html', form=form)
예제 #21
0
 def register(self):
     form = RegistrationForm(request.form)
     if request.method == 'POST' and form.validate():
         user = Ormuco(form.name.data, form.color.data, form.pet.data)
         try:
             self.dbsession.add(user)
             self.dbsession.commit()
             flash('Thanks for registering')
             return redirect('/')
         except:
             self.dbsession.rollback()
             flash('Duplicate name. Choose another')
     return render_template('base.html', form=form)
예제 #22
0
def register():
    if request.method == "POST":
        myform = RegistrationForm(request.form["studentno"],
                                  request.form["username"],
                                  request.form["password"],
                                  request.form["name"],
                                  request.form["surname"])
        if request.form["opt"] == "student":
            try:
                connection = db.connect(url)
                cursor = connection.cursor()
                statement = """INSERT INTO student(st_id, username, password, name, surname, grade)
                                    VALUES({}, \'{}\', \'{}\', \'{}\', \'{}\', {});""".format(
                    myform.studentno, myform.username, myform.password,
                    myform.name, myform.surname, int(request.form["grade"]))
                print(statement)
                cursor.execute(statement)
                connection.commit()
                statement = """INSERT INTO FINANCE(paid, topay, studentno, last_confirmed, isConfirmed) Values(DEFAULT, DEFAULT, {}, -1, 'f');""".format(
                    request.form["studentno"])
                cursor.execute(statement)
                connection.commit()
                #result = cursor.fetchone()
                cursor.close()
                flash('Your account was created successfully')
                return redirect(url_for('home_page'))
            except db.DatabaseError:
                connection.rollback()
                flash('Unsuccessful', 'danger')
            finally:
                connection.close()
        elif request.form["opt"] == "teacher":
            try:
                connection = db.connect(url)
                cursor = connection.cursor()
                statement = """INSERT INTO teachers(code, username, password, name, surname)
                                    VALUES({}, \'{}\', \'{}\', \'{}\', \'{}\');""".format(
                    myform.studentno, myform.username, myform.password,
                    myform.name, myform.surname)
                print(statement)
                cursor.execute(statement)
                connection.commit()
                cursor.close()
                flash('Your account was created successfully')
                return redirect(url_for('home_page'))
            except db.DatabaseError:
                connection.rollback()
                flash('Unsuccessful', 'danger')
            finally:
                connection.close()
    return render_template('register.html')
예제 #23
0
파일: app.py 프로젝트: xayyuu/daytodo
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, 'Confirm Your Account',
                   'email/confirm', user=user, token=token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
예제 #24
0
파일: user.py 프로젝트: dbdoer/ioa
    async def registration(request):
        session = await get_session(request)
        post = await request.post()
        form = RegistrationForm(post)

        if "POST" == request.method and form.validate():
            try:
                user = await user_service.register(form.data)
                session['user_id'] = user['id']
                return web.HTTPFound("/")
            except DuplicatedUser as e:
                form.username.errors.append(e)

        return {"form": form}
예제 #25
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    _password=form.password.data,
                    _email=form.email.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #26
0
def createlogin():
    status_code = 200
    form2 = RegistrationForm(request.form)
    if request.method == 'POST':
        if not form2.validate():
            flash("The entry is not valid, plz retry")
        else:
            # user=User(name=form2.username.data,password=form2.password.data)
            # db_session.add(user)
            # print((request.form['username'],request.form['password']))
            # db_session.commit()
            # flash("User created successfully")
            return redirect(url_for('login'))
    return render_template('createlogin.html', form2=form2,
                           error=None), status_code
예제 #27
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('all_donation'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pass = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        new_donor = Donor(username=form.username.data,
                          name=form.name.data,
                          password=hashed_pass)
        new_donor.save()
        flash(f'Account created for {form.name.data}!, you can now log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.jinja2', title='register', form=form)
예제 #28
0
def Register():
    registration_form = RegistrationForm()
    if registration_form.submit2.data and \
        registration_form.validate_on_submit():
        user = (db_session.query(User).filter_by(
            email=registration_form.email.data).first())
        if user is None:
            new_user = User(name=registration_form.name.data,
                            email=registration_form.email.data)
            new_user.password = registration_form.password.data
            db_session.add(new_user)
            db_session.commit()
            flash('Registration successful. \
                Please Log in with the credentials')
            return redirect(url_for('Home'))
        flash('User already exists. Please log in')
    return render_template('register.html', form=registration_form)
예제 #29
0
def registration():
    registration_form = RegistrationForm()
    if registration_form.validate_on_submit():
        email = request.form.get('email')
        name = request.form.get('name')
        password = request.form.get('password')

        user = User.query.filter_by(email=email).first()
        if user:
            flash('Email already exist')
            return redirect(url_for('auth.registration'))
        new_user = User(email=email, name=name, password=generate_password_hash(password=password, method='sha256'))
        db.session.add(new_user)
        db.session.commit()
        flash('Thanks for registartion')
        return redirect(url_for('auth.login'))
    return render_template('registration.html', form=registration_form)
예제 #30
0
def register():
    if request.method == 'GET':
        form = RegistrationForm()
        return render_template('register.html', title='注册', form=form)

    username = request.form['username']
    password = request.form['password']
    nick_name = request.form['nick_name']
    if username is None or password is None or nick_name is None:
        flash('Invalid')
        return redirect('/register/')

    user = User(username=username, nick_name=nick_name)
    user.set_password(password)
    db.session.add(user)
    db.session.commit()
    flash('register ok')
    return redirect('/login')