Beispiel #1
0
def loginn():
    '''
    Login endpoint
    '''
    form_login = LoginForm()
    form_register = RegisterForm()

    if request.method == 'POST':
        if form_login.validate_on_submit():
            new = User.query.filter_by(
                username=form_login.username.data).first()
            if new is not None:
                if check_password_hash(new.password, form_login.password.data):
                    login_user(new, remember=form_login.remember.data)
                    return redirect(url_for('index'))
                else:
                    flash('Username or password is incorect')
            else:
                flash('Username or password is incorect')
    else:
        if current_user.is_authenticated:
            return redirect(url_for('index'))

    return render_template('login.html',
                           form_login=form_login,
                           form_register=form_register)
Beispiel #2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for user {}, remember me={}'.format(
            form.username.data, form.remember_me.data))
        return redirect('/triedtologin')
    return render_template('login.html', title='Sign In', form=form)
Beispiel #3
0
def login():
    error = None
    form = LoginForm(request.form)
    if form.validate_on_submit():
        email = form.email.data
        password = hashlib.sha384(form.password.data.encode()).hexdigest()
        
        params = {"data": {"email": email,    
                       "password":password
                       },
              "request": "login"}
        res = requests.post(userDataCloudURL, json=params)
        data = {}
        print(res.text)
        # data = json.loads(res.text)
        status = res.status_code
        if(status==200):
            data = json.loads(res.text)
            putDataIntoSession(data)
            session["loggedin"] = True
            return redirect("/")
        elif(status==401 or status==404):
            flash("Invalid credentials","error")
            form = LoginForm(request.form)
            return render_template(loginURL, form=form)
        elif status==500:
            return ("500 error. Please contact your server administrator.")
        return(data)
    return render_template(loginURL, form=form)
Beispiel #4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        login_user(form.user)
        flash('You are logged successfully.', 'info')
        return redirect(request.args.get('next') or url_for('index'))
    return redirect(url_for('index'))
Beispiel #5
0
def register():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = request.form.get('username',None)
        password = request.form.get('password',None)

        user = User(user_name)
        user.password = password
        return redirect(url_for('register_success'))
    return render_template('register.html', title="Register", form=form)
Beispiel #6
0
def login():
    """
    登陆页面
    """
    form = LoginForm()
    if form.validate_on_submit():
        username = form.name.data
        password = form.password.data
        if username == 'wangyuankun' and password == 'wangyuankun1993':
            return redirect(url_for('index'))
    return render_template('login.html', form=form)
Beispiel #7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = request.form.get('username', None)
        password = request.form.get('password', None)
        remember_me = request.form.get('remember_me', False)


        user = User(user_name)
        if user.verify_password(password):
            login_user(user)
            return redirect(url_for('main'))
    return render_template('login1.html', title="Sign In", form=form)
Beispiel #8
0
def login():
	if (current_user.is_authenticated == True):
		return redirect(url_for('home'))		
	form = LoginForm()
	
	if form.validate_on_submit():
		user = Account.query.filter_by(email = form.email.data).first()
		if user:
			if check_password_hash(user.pswd, form.password.data):
				login_user(user)
				return redirect(url_for('home'))
		return  'Invalid username or password'
	return render_template('login.twig', form=form, title='Sign in')
Beispiel #9
0
def login():
    form = LoginForm()
    error = None
    if form.validate_on_submit():
        # security check (may not be needed)
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                session['logged_in'] = True
                # render_template('dashboard.html', form=form)
                return redirect(url_for('dashboard', user=user))
        error = 'Invalid username or password.'
    return render_template('login.html', form=form, error=error)
Beispiel #10
0
def login():
    """Show user the login form; handle login."""

    form = LoginForm()

    if form.validate_on_submit():

        username = form.data.get("username").upper()
        password = form.data.get("password")

        user = User.authenticate(username, password)
        if user:
            session['password'] = password
            flash(f"Hello, {user.get_firstname()}", 'success')
            return redirect(url_for('index'))
        else:
            flash("Please double check your username and password!", 'danger')

    return render_template("login_form.html", form=form)
Beispiel #11
0
def login():
    form = LoginForm(request.form)

    if not form.validate_on_submit():
        return render_template('login.html', form=form)
    if request.method == 'POST':
        # Storing the Logged in user
        user = User.query.filter_by(email=form.email_addr.data).first()

        # If no user is found, then they might have entered the wrong credentials
        # If the user entered the correct username, but the wrong password, error is shown
        if user is None:
            return render_template('login.html', form=form, message="Incorrect Username or Password")
        elif user.password == form.password.data:   
            # Confirming the user logged in
            user.auth = True
            db.session.commit()
            return render_template('index.html', form=form, loggedin=True)
        else:
            return render_template('login.html', form=form, message="Incorrect Password", loggedin=False)
Beispiel #12
0
def login():
    # LOGIN HANDLER
    form = LoginForm()
    if session.get('logged_in'):
        if session['logged_in'] is True:
            return redirect(url_for('home', title='Home'))

        user = mongo.db.users.find_one({'email': form.email.data})

        if form.validate_on_submit():
            user = mongo.db.users
            db_user = user.find_one({'email': request.form['email']})

            if db_user:
                if bcrypt.hashpw(request.form['password'].decode('utf-8'),
                                 db_user['password']) == db_user['password']:
                    session['email'] = request.form['email']
                    session['logged_in'] = True

                return redirect(url_for('home', title='Account'))
        else:
            flash('Login Failed.. Please Check Yourself!', 'danger')
    return render_template('login.html', title='Log In', form=form)