예제 #1
0
파일: app.py 프로젝트: wenxiangcai/python-
def login():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.username.data==username and form.password.data==password:
            return render_template("admin.html",r=1,data="请输入网站域名",isactive1="active")
        else:
            return render_template('base.html',data="pass_error")
    elif request.method == 'POST' and not form.validate():
            return render_template("base.html",data="not_legitimate")
    else:
        return render_template('index.html')
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
0
    def POST(self):
        user = account.get_current_user()
        google = googlelogin.GoogleLogin()
        next = web.ctx.path
        google_url = google.get_redirect_url(state=next)

        form = RegistrationForm(web.webapi.rawinput())
        if user and form.validate():
            self.add_member(user, form.data)
            return render_template("index.html", form=form, user=user, google_url=google_url, done=True)
        else:
            return render_template("index.html", form=form, user=user, google_url=google_url, simple=self.USE_SIMPLE_FORM)
예제 #7
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)
예제 #8
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}
예제 #9
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}
예제 #10
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
예제 #11
0
def register():
    try:
        form = RegistrationForm(csrf_enabled=False)
        if request.method == "POST":
            if form.validate() == False:
                flash('All fields are required.')
                return render_template('register.html',form=form)
            else:
                firstname = form.firstname.data
                lastname = form.lastname.data
                gender = form.gender.data
                email = form.email.data
                password = bcrypt.generate_password_hash((str(form.password.data)))

                c, conn = connection()
                x = c.execute("SELECT * FROM user WHERE email = '"+thwart(email)+"'")


                if int(x) > 0:
                    flash("That email is already taken, please choose another")
                    return render_template('register.html', form=form)

                else:
                    c.execute("INSERT INTO user (email, password,first_name ,last_name, gender) VALUES (%s, %s, %s, %s,%s)",
                             (thwart(email),thwart(password), thwart(firstname), thwart(lastname), thwart(gender)))
                    
                    conn.commit()
                    flash("Thanks for registering!")
                    c.execute("SELECT user_id FROM user WHERE email = '"+thwart(email)+"'")
                    data = c.fetchone()[0]
                    c.close()
                    conn.close()
                    gc.collect()

                    session['logged_in'] = True
                    session['user'] = email
                    session['user_id'] =  str(data)
                    return render_template("home.html")

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

    except Exception as e:
        return(str(e))
예제 #12
0
def register():
    form = RegistrationForm()
    if request.method == 'POST' and form.validate():
        usr = request.form['username']
        pwd = request.form['password']
        role = request.form['role']

        if usr and pwd and role:
            user = models.User.query.filter_by(username=usr).first()
            if (user == None):
                user = models.User(username=usr, role_id=role)
                user.set_password(pwd)
                # add employee to the database
                db.session.add(user)
                db.session.commit()
                flash('You have successfully registered! You may now login.',
                      'success')
                return redirect(url_for('login'))
            else:
                flash('User with given Username already exists.', 'danger')
    return render_template('register.html', form=form)
예제 #13
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate() and form.post_validate():
        account_status = None
        account_type = None
        if not len(User.query.filter(User.account_status == 1).all()):
            account_status = 1
            account_type = 2

        # Building user profile from WTFoprms input and Google profile data
        profile = User(name=session['profile_name'],
                       nickname=form.nickname.data,
                       ext_id=session['profile_ext_id'],
                       avatar_url=session['profile_picture'],
                       email=session['profile_email'],
                       birthday=form.birthday.data,
                       account_status=account_status,
                       account_type=account_type)

        # The session might not contain any google profile data.
        # To avoid it, the user id is hashed and this hash is used as the key.
        session['profile_ext_id_hashed'] = hash_id(session['profile_ext_id'])
        session.pop('profile_ext_id')
        session.pop('profile_name')
        session.pop('profile_email')
        session.pop('profile_picture')
        try:
            db.session.add(profile)
            db.session.commit()
            return redirect('home')
        except KeyError:
            db.session.rollback()
            session.clear()
            return redirect(url_for('index'))
        except IntegrityError:
            db.session.rollback()
            session.clear()
            return redirect(url_for('index'))

    return render_template('register.html', form=form, register=True)
예제 #14
0
def trap_registration():
    form = RegistrationForm(request.form, csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        return redirect(url_for('success', challenge="registration"))
    return render_template('traps/registration.html', form=form)
예제 #15
0
def trap_registration():
    form = RegistrationForm(request.form, csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        return redirect(url_for('success', challenge="registration"))
    return render_template('traps/registration.html', form=form)