Exemplo n.º 1
0
def signin():
    """Form for signing into the app, once you have created an account."""

    #Flask WTForms
    form = SigninForm(request.form)

    #Once they are signed in, redirect to profile
    if 'username' in session:
        return redirect(url_for('profile'))

    #If not signed in yet, make sure the form validates. Then save the following into the session.
    if request.method == "POST":
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['username'] = form.username.data
            user = User.query.filter(
                User.username == form.username.data.lower()).first()
            session['email'] = user.email
            session['id'] = user.user_id
            session['picture'] = user.picture
            return redirect(url_for('profile'))

    elif request.method == "GET":
        return render_template('signin.html', form=form)
Exemplo n.º 2
0
def signin():
    title = 'Login'
    form = SigninForm()
    # If user is signed in
    if 'email' in session:
        return redirect(url_for('profile'))

    if request.method == 'POST':
        auser = AdminUser.query.filter_by(email = form.email.data.lower()).first()

        # Admin login
        if auser and auser.check_password(form.password.data):
            session['email'] = 'admin'
            return redirect('/admin')

        elif form.validate() == False:
            return render_template('signin.html',title = title, form=form)

        else:
            # return "hello!"
            session['email'] = form.email.data
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signin.html',title = title, form=form)
Exemplo n.º 3
0
def signin():

  """
  Routing to signin.html

  Returns:
    POSTS:
      Signin.html: when form not valid
      Admin_dashboard: When form valid.
        sets cookies with email, accessLvl
    GET:
      Signin.html

  """
  form = SigninForm()
   
  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      user = User.query.filter_by(email=form.email.data).first()
      session['email'] = form.email.data
      session['accessLvl'] = user.accessLvl
      return redirect(url_for('admin_dashboard'))
                 
  elif request.method == 'GET':
    return render_template('signin.html', form=form)
Exemplo n.º 4
0
def signin():
    form = SigninForm()

    if "email" in session:
        return redirect(url_for("welcome", form=form))

    if request.method == "POST":
        if form.validate() == False:
            return render_template("signin.html", form=form)
        else:
            session["email"] = form.email.data
            signin = User.query.filter_by(email=session["email"]).first()
            if signin:
                session["lastname"] = db_session.query(User.lastname).filter(User.email == session["email"]).first()
                session["firstname"] = db_session.query(User.firstname).filter(User.email == session["email"]).first()
                session["phone"] = db_session.query(User.phone).filter(User.email == session["email"]).first()
                session["country_id"] = db_session.query(User.country_id).filter(User.email == session["email"]).first()
            session["lastname"] = session["lastname"]
            session["firstname"] = session["firstname"]
            session["phone"] = session["phone"]
            session["country_id"] = session["country_id"]

            if session["country_id"] == db_session.query(User.country_id).filter(User.country_id == 1).first():
                session["country_id"] == "Nigerian"
            else:
                session["country_id"] == "Foreigner"

            return redirect(url_for("welcome", form=form))

    elif request.method == "GET":
        return render_template("signin.html", form=form)
def signin():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = SigninForm()

    if request.method == 'GET':
        return render_template('signin.html', form=form)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            username = form.username.data
            password = form.password.data

            user_from_table = User.query.filter_by(username=username).first()

            if user_from_table:
                if user_from_table.check_password(password):
                    login_user(user_from_table,
                               remember=form.remember.data)  #added
                    flash("Successful signin!")
                    return redirect(url_for('home'))
                else:
                    flash("This password is incorrect.")
                    return redirect(url_for('signin'))
            else:
                flash("This username doesn't exist.")
                return redirect(url_for('signin'))
Exemplo n.º 6
0
def sign_in():
    form = SigninForm(request.form)
    if request.method == 'POST' and form.validate():
        session["sign_in"] = True
        session["username"] = form.username.data
        flash("Hello {user}!".format(user=session["username"]))
        return redirect(url_for('index'))
    return render_template('sign_in.html', form=form)
Exemplo n.º 7
0
def signin():
    rform = SigninForm(request.form, prefix="SigninForm")
    if request.method == 'POST':
        if rform.validate() == False:
            return render_template('index.html',
                                   rform=rform,
                                   lform=SignupForm())
        else:
            return "signig"
Exemplo n.º 8
0
def signin():
    form = SigninForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile'))             
    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 9
0
def signin():
    form = SigninForm()
    if request.method == 'POST':
        if not form.validate():
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 10
0
def login():
	form=SigninForm()

	if request.method=='POST': #do the login
		if form.validate()==False:
			return render_template('login.html',form=form)
		else:
			session['email']=form.email.data
			return redirect('/s1')			
	else: #show login form
		return render_template('login.html',form=form)
Exemplo n.º 11
0
def signin():
    signin_form = SigninForm()
    if request.method == 'POST':
        if signin_form.validate() == False:
            return render_template('signin.html', form=signin_form)
        else:
            session['email'] = signin_form.email.data
        return redirect(url_for('index'))

    elif request.method == 'GET':
        return render_template('signin.html', form=signin_form)
Exemplo n.º 12
0
def handle_signin():
    signin_form = SigninForm()
    register_form = RegisterForm()
    if signin_form.validate() and signin_form.submit1.data:
        username = signin_form.username.data
        flash('%s,You just submit signin_form!' % username)
        print('%s,You just submit signin_form!' % username)
        return redirect(url_for('index'))
    return render_template('2form2view.html',
                           signin_form=signin_form,
                           register_form=register_form)
Exemplo n.º 13
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()

    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash('%s, you just submit the signinForm' % username)
        return redirect(url_for('index'))
    if register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash('%s, you just submit the RegisterForm' % username)
        return redirect(url_for('index'))
    return render_template('')
Exemplo n.º 14
0
def signin():
    form = SigninForm()
    
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form = form)
        else:
            user = db.session.query(User).filter(User.email == form.email.data).first()
            session['uid'] = user.user_id
            return redirect(url_for('user_timeline', uid=session['uid']))
    
    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 15
0
def signin():
    form = SigninForm()
   
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['screenname'] = form.screenname.data
            user = db.Users.find({'screenname':session['screenname']})
            return redirect(url_for('profile'))
                 
    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 16
0
def signin():
    form = SigninForm()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['screenname'] = form.screenname.data
            user = db.Users.find({'screenname': session['screenname']})
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 17
0
def signin():
    form = SigninForm()
    if 'email' in session:
        return redirect(url_for('post_event'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('login.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('post_event'))

    elif request.method == 'GET':
        return render_template('login.html', form=form)
Exemplo n.º 18
0
def signin():
    form = SigninForm()
      
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            flash('You are logged in')
            print (str(session['email']),'is logged in') 
        return redirect(url_for('home'))
                
    elif request.method == 'GET':
        return render_template('signin.html', form=form)      
Exemplo n.º 19
0
def index():
    if 'email' in session:
        return redirect(url_for('profile'))
    form = SigninForm()
        
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('index.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile'))
                
    elif request.method == 'GET':
        return render_template('index.html', form=form)
Exemplo n.º 20
0
def signin():
    form = SigninForm()

    if 'email' in session:
        return redirect(url_for('profile'))

    if request.method == "POST":
        if form.validate() == False:
            return render_template("signin.html", form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile'))

    elif request.method == "GET":
        return render_template("signin.html", form=form)
Exemplo n.º 21
0
def signin():
    if 'email' in session:
        return redirect(url_for('contacts'))

    form = SigninForm()

    if request.method == 'POST':
        if form.validate(db) == False:
            return render_template('home.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('contacts'))

    elif request.method == 'GET':
        return render_template('home.html', form=form)
Exemplo n.º 22
0
def login():
    form = SigninForm(db=db)
    if 'email' in session:
        return redirect(url_for('perfil'))
   
    if request.method == 'POST':
        if form.validate(db) == False:
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            user = db.session.query(User).filter_by(email = session['email']).first()
            session['uid']=user.uid #guardo el id en la sesion para luego usarlo en las relaciones BD
            return redirect(request.args.get("next") or url_for("perfil"))
    else:
        return render_template('signin.html', form=form) 
Exemplo n.º 23
0
def signin():
  if 'email' in session:
    return redirect(url_for('contacts'))

  form = SigninForm()

  if request.method == 'POST':
    if form.validate(db) == False:
      return render_template('home.html', form=form)
    else:
      session['email'] = form.email.data
      return redirect(url_for('contacts'))

  elif request.method == 'GET':
    return render_template('home.html', form=form)
Exemplo n.º 24
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()

    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash('%s, you just submit the Signin Form.' % username)
        return redirect(url_for('index'))

    if register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash('%s, you just submit the Register Form.' % username)
        return redirect(url_for('index'))

    return render_template('2form.html', signin_form=signin_form, register_form=register_form)
Exemplo n.º 25
0
def signin():
    form = SigninForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            user = User.query.filter_by(email=session['email']).first()
            login_user(user)
            flash('Logged in successfully!')
            session['votes'] = []
            return redirect(url_for('profile'))
    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 26
0
def signin():
  form = SigninForm()

  if 'username' in session:
    return redirect(url_for('dashboard'))

  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      session['username'] = form.username.data
      return redirect(url_for('dashboard'))

  elif request.method == 'GET':
    return render_template('signin.html', form=form)
Exemplo n.º 27
0
def signin():
    form = SigninForm()

    if 'email' in session:
        return redirect(url_for('profile'))

    if request.method == "POST":
        if form.validate() == False:
            return render_template("signin.html", form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile'))

    elif request.method == "GET":
        return render_template("signin.html", form=form)
Exemplo n.º 28
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()
    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash('%s,You just submit signin_form!' % username)
        print('%s,You just submit signin_form!' % username)
        return redirect(url_for('index'))
    elif register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash('%s,You just submit register_form!' % username)
        print('%s,You just submit register_form!' % username)
        return redirect(url_for('index'))
    return render_template('2form.html',
                           signin_form=signin_form,
                           register_form=register_form)
Exemplo n.º 29
0
def signin():

  form = SigninForm()
  if authenticate():
    return redirect(url_for('profile'))

  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      session['admin_call_code'] = form.admin_call_code.data
      # print session['admin_call_code']
      return redirect(url_for('profile'))
                 
  elif request.method == 'GET':
    return render_template('signin.html', form=form)  
Exemplo n.º 30
0
def manyform():
    register_form = RegisterForm()
    login_form = SigninForm()
    # if register_form.validate_on_submit():
    if register_form.submit2.data and register_form.validate():
        flash('you just submit the register Form.')
        print(register_form.data)
        print(login_form.data)
    # if login_form.validate_on_submit():
    if login_form.submit1.data and login_form.validate():
        flash('you just submit the Login Form.')
        print(register_form.data)
        print(login_form.data)
    return render_template('manyform.html',
                           register_form=register_form,
                           login_form=login_form)
Exemplo n.º 31
0
def signin():
    form = SigninForm()

    if 'username' in session:
        return redirect(url_for('home'))

    if request.method == 'POST':
        if not form.validate():
            return render_template('signin.html', form=form)
        else:
            session['username'] = form.username.data
            flash('Login Successful.')
            return redirect(url_for('home'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 32
0
Arquivo: views.py Projeto: Teezus/T
def signin():
  form = SigninForm()
  
  #POST means that they are signing in 
  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      session['email'] = form.email.data
      user = User.query.filter_by(email=form.email.data).first()
      user.last_seen = datetime.datetime.now()
      db.session.commit()
      return redirect(url_for('profile'))
  #GET means that they want to login
  elif request.method == 'GET':
    return render_template('signin.html', form=form)
Exemplo n.º 33
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()

    # 不需要管 HTTP 请求方法,如果是 GET 请求,data 就会是 False
    # 所以也不需要使用 validate_on_submit 这种复杂的方法
    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash('%s, you just submit the Signin Form.' % username)
        return redirect(url_for('index'))

    if register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash('%s, you just submit the Register Form.' % username)
        return redirect(url_for('index'))

    return render_template('2form.html', signin_form=signin_form, register_form=register_form)
Exemplo n.º 34
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()

    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash(f'{username}, you just submit the Signin Form.')
        return redirect(url_for('index'))

    if register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash(f'{username}, you just sumbit the Register Form.')
        return redirect(url_for('index'))

    return render_template('2form.html',
                           signin_form=signin_form,
                           register_form=register_form)
Exemplo n.º 35
0
def signin():
    if end():
        return render_template('home.html', title="Contest ended", msg="Contest ended", en=True)

    form = SigninForm()
    if 'reg' in session:
        return redirect(url_for('next'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form, title="signin")
        else:
            session['reg'] = form.reg.data
            return redirect(url_for('next'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form, title="signin")
Exemplo n.º 36
0
def home():
    form = SigninForm()
    if 'uid' in session:
        return redirect(url_for('profile1'))
    #form.email.errors=None
    #form.password.errors=None

    if request.method == "POST":
        if form.validate() == False:
            print 'coming here..post'
            return render_template('home.html', form=form)
        else:
            try:
                session.regenerate()
            except:
                print 'session.regenerate error'

            session['firstname'] = form.data_firstname()
            session['lastname'] = form.data_lastname()
            session['companyname'] = form.data_companyname()
            session['phone'] = form.data_phone()
            session['email'] = form.email.data

            session['uid'] = str(uuid.uuid4())
            session['desc_html'] = None

            session['sandbox'] = SANDBOX
            session['prebuilt'] = PREBUILT

            session['session_dir'] = session['sandbox'] + '/' + session['uid']
            session['prebuilt_dir'] = session['prebuilt']
            createSessionDirectory(session['session_dir'])
            session['train_filenames'] = []
            session['test_filenames'] = []

            obj = acs.DataAnalytics(session['uid'], session['session_dir'])
            session['data_object'] = obj
            session['prebuilt_dict'] = prebuiltDict()

            session.modified = True
            #return render_template('agreement.html')
            return redirect(url_for('profile1'))

    elif request.method == 'GET':
        return render_template('home.html', form=form)
Exemplo n.º 37
0
def home():
	form = SigninForm()
	
	if 'email' not in session:
		sessioned=False
	else:
		sessioned=True

	if request.method == 'POST':
		if form.validate() == False:
			return render_template('home.html', form=form, sessioned=sessioned)
		else:
			session['email'] = form.email.data
			sessioned=True
			return redirect(url_for('dash'))
			
	elif request.method == 'GET':
		return render_template('home.html', form=form, sessioned=sessioned)
Exemplo n.º 38
0
def signin():

    form = SigninForm()

    if 'uid' in session:
        print 'email found'

        return redirect(url_for('profile1'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            return redirect(url_for('profile1'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 39
0
def multi_form():
    signin_form = SigninForm()
    register_form = RegisterForm()

    # 提交登录表单并且进行验证
    if signin_form.submit1.data and signin_form.validate():
        username = signin_form.username.data
        flash('%s, you just submit the Signin Form.' % username)
        return redirect(url_for('index'))

    # 提交注册表单并且进行验证
    if register_form.submit2.data and register_form.validate():
        username = register_form.username.data
        flash('%s, you just submit the Register Form.' % username)
        return redirect(url_for('index'))

    return render_template('2form.html',
                           signin_form=signin_form,
                           register_form=register_form)
def login():
    form = SigninForm()
    form1 = CaptchaForm()

    if request.method == 'POST':
        if form1.validate_on_submit() == True:
            if form.validate() == False:
                return render_template('login.html', form=form, form1 = form1)
            else:
                session['nickname'] = form.nickname.data
                user = User.query.filter_by(nickname = session['nickname']).first()
                session['password'] = user.pwdhash
                return redirect(url_for('files'))
        else:
            flash(u'Wprowadź Captcha.')
            return render_template('login.html', form=form, form1 = form1)

    elif request.method == 'GET':
        return render_template('login.html', form=form, form1=form1)
Exemplo n.º 41
0
def signin():
  form = SigninForm()

  if 'username' in session:
    return redirect(url_for('dashboard'))

  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      session['username'] = form.username.data
      user = User.query.filter_by(username = session['username']).first()
      if user.portfolioname == None or len(user.portfolioname.replace(' ', '')) < 1:
        return redirect(url_for('portfolioSetup'))
      else:
        return redirect(url_for('dashboard'))

  elif request.method == 'GET':
    return render_template('signin.html', form=form)
Exemplo n.º 42
0
def signin():
  form = SigninForm()
  if 'email' in session:
    return redirect(url_for('welcome', form=form)) 
      
  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signin.html', form=form)
    else:
      session['email'] = form.email.data
      signin = User.query.filter_by(email = session['email']).first()
      if signin:
        signin = db_session.query(User.lastname).filter(User.email == session['email']).first()
        signfirst = db_session.query(User.firstname).filter(User.email == session['email']).first()
        signphone = db_session.query(User.phone).filter(User.email == session['email']).first()
        signcountry_id = db_session.query(User.country_id).filter(User.email == session['email']).first()
      return redirect(url_for('storedata', form=form))             
  elif request.method == 'GET':
    return render_template('signin.html', form=form)
Exemplo n.º 43
0
def signin():
    form = SigninForm()

    if 'username' in session:
        return redirect(url_for('dashboard'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['username'] = form.username.data
            user = User.query.filter_by(username=session['username']).first()
            if user.portfolioname == None or len(
                    user.portfolioname.replace(' ', '')) < 1:
                return redirect(url_for('portfolioSetup'))
            else:
                return redirect(url_for('dashboard'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 44
0
def signin():
    form = SigninForm()
   
    if request.method == 'POST':
        
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            session['email'] = form.email.data
            user =User.query.filter_by(email=form.email.data).first()
            if user is None:
                flash('Username or Password is invalid' , 'error')
                return redirect(url_for('signin'))
            remember_me=1
            login_user(user)
            flash('Logged in successfully')
            return redirect(url_for('index'))
                 
    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 45
0
def signin():

    form = SigninForm()
    if "email" in session:
        return redirect(url_for("owner_dashboard"))
    if request.method == "POST":
        if form.validate() == False:
            return render_template("signin.html", form=form)
        else:
            session["email"] = form.email.data
            user = Broker.query.filter_by(email=session["email"]).first()
            if user is None:
                session["type"] = "owner"
                return redirect(url_for("owner_dashboard"))
            else:
                session["type"] = "broker"
                return redirect(url_for("broker_dashboard"))

    elif request.method == "GET":
        return render_template("signin.html", form=form)
Exemplo n.º 46
0
def signin():
    # check if already logged in
    if 'user_id' in session:
        return redirect(url_for('index'))

    # login form
    login = SigninForm()
    if request.method == "POST":
        if login.validate() == False:
            return render_template("users/signin.html", form=login)
        else:
            email = login.email.data
            password = login.password.data
            user = User.query.filter_by(email=email).first()
            if not user:
                e = list(login.email.errors)
                e.append('Invalid email.')
                login.email.errors = tuple(e)
                return render_template('users/signin.html', form=login)
            elif user.pwdhash == 'FORCE_RESET':
                token = SubmitEmail()
                force_reset = """
                    We need you to reset your password.
                    There is nothing to worry about, it is just part of the website revamp.
                    You may use the same password as before.
                """
                return render_template('users/reset_token.html', form=token, message=force_reset)
            elif user is not None and user.check_password(password):
                session['user_id'] = user.user_id
                session['email'] = login.email.data
                session['username'] = user.first_name + ' ' + user.last_name
                session['logged_in'] = True
                return redirect(url_for('index'))
            else:
                e = list(login.password.errors)
                e.append('Incorrect password.')
                login.password.errors = tuple(e)
                return render_template('users/signin.html', form=login)

    elif request.method == "GET":
        return render_template('users/signin.html', form=login)
Exemplo n.º 47
0
def signin():
    if 'email' in session:
        return  redirect(url_for('home'))
    form = SigninForm()

    if request.method == "POST":
        if form.validate() == False:
            return render_template('signin.html', form=form)
        else:
            email = form.email.data
            password = form.password.data

            user = User.query.filter_by(email=email).first()
            if user is not None and user.check_password(password):
                session['email'] = form.email.data
                return redirect(url_for('home'))
            else:
                return redirect(url_for('signin'))

    elif request.method == 'GET':
        return render_template('signin.html', form=form)
Exemplo n.º 48
0
def signin():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))

    form = SigninForm(request.form)
   
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email = form.email.data).first()
        session['remember_me'] = form.remember_me.data
        session['email'] = form.email.data
        login_user(user)
        flash('Welcome Back')
        return redirect(url_for('profile'))
    
    # if 'remember_me' in session:
    #     remember_me = session['remember_me']
    #     session.pop('remember_me', None)
    # login_user(g.user, remember=remember_me)
    # return redirect(request.args.get('next') or url_for('profile'))

    return render_template('signin.html', form=form)
Exemplo n.º 49
0
def login():
    with app.app_context():
        signinForm = SigninForm()
    if request.method == 'POST':
        if not signinForm.validate():
            return render_template('login.html', signinForm=signinForm)
        else:
            user = User.query.filter_by(
                email=signinForm.email.data.lower()).first()
            session['email'] = signinForm.email.data
            session['username'] = user.username
            session['logged_in'] = True
            session['user_id'] = user.id
            session['level'] = user.level
            if user.level == 1:
                session['is_company'] = False
            elif user.level == 2:
                session['is_company'] = True

            return redirect(url_for('main'))
    elif request.method == 'GET':
        return render_template('login.html', signinForm=signinForm)
Exemplo n.º 50
0
Arquivo: website.py Projeto: pmn/qi.io
def sign_in():
    """Sign the user in"""
    form = SigninForm()
    user = None
    if request.method == "POST" and form.validate():
        # Log the user in
        username = request.form["username"]
        password = request.form["password"]

        assert isinstance(username, basestring)
        assert isinstance(password, basestring)

        user = User(username)
        if user.authenticate(password):
            session["user"] = user
            logging.info("User signed in: {}".format(username))
            return redirect(url_for("page"))
        else:
            flash("Incorrect username or password")
            logging.info("Incorrect username or password for user: {}".format(username))
            return render_template("signin.html", form=form, user=user)
    return render_template("signin.html", form=form, user=user)
Exemplo n.º 51
0
def signin():
    """Form for signing into the app, once you have created an account."""

    #Flask WTForms
    form = SigninForm(request.form)

    #Once they are signed in, redirect to profile
    if 'username' in session:
        return redirect(url_for('profile'))

    #If not signed in yet, make sure the form validates. Then save the following into the session.
    if request.method == "POST":
        if form.validate()==False:
            return render_template('signin.html', form=form)
        else:
            session['username']= form.username.data
            user = User.query.filter(User.username==form.username.data.lower()).first()
            session['email']= user.email
            session['id'] = user.user_id
            session['picture'] = user.picture
            return redirect(url_for('profile'))

    elif request.method == "GET":
        return render_template('signin.html', form=form)
Exemplo n.º 52
0
 def post(self):
     form = SigninForm(self.request.arguments)
     if form.validate():
         self.set_current_user(form.user)
         return self.redirect(self.next_url)
     return self.render("user/signin.html", form=form)
Exemplo n.º 53
0
 def post(self):
     form = SigninForm(self.request.arguments)
     if form.validate():
         self.set_current_user(form.user)
         return self.redirect(self.next_url)
     return self.render("user/signin.html", form=form)