コード例 #1
0
ファイル: pages.py プロジェクト: michlee1337/panorama
def login():
    """
    User login

    A GET request will redirect to the login view.

    A POST request will check for valid login data.
    Valid login data requires existing user instance with
    matching username, password, and email.
    Success/ failure will result in redirect to homepage/ login respectively.
    """
    form = LoginForm()
    if request.method == 'GET':
        if current_user.is_authenticated:
            return redirect('/')
        else:
            return render_template('pages/login.html', form=form)
    elif request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is None or not user.check_password(form.password.data):
                flash('Invalid username or password')
                return redirect(url_for('pages.login'))
            login_user(user)
            flash('Logged in successfully.')
            return redirect('/')
        else:
            flash('Provided login details not recognized.')
            return render_template('pages/login.html', form=form)
コード例 #2
0
ファイル: app.py プロジェクト: elmerihyvonen/ImageService
def login():

    # if user is already logged in
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()

    if form.validate_on_submit():
        username = request.form['username']
        password = request.form['password']

        find_user = Database.find_one('users', {'username': username})

        # checks if the login is valid
        if User.login_valid(username, password, bcrypt):

            log_user = User(find_user['username'], find_user['password'],
                            find_user['profile_image'], find_user['_id'])
            login_user(log_user, remember=form.remember.data)
            next_page = request.args.get('next')
            User.login(username)
            flash('Login successful', 'success')

            return redirect(next_page) if next_page else redirect(
                url_for('home'))

        # if login was not valid session['email'] should be None
        else:
            session['username'] = None
            flash('Check your credentials.', 'danger')

    return render_template('login.html', title='Login', form=form)
コード例 #3
0
def password_verification():
    """
    Display website with login form. If correct password is submitted redirects to main_page

    :return: form page id failed counter is valid or blocking page if is not
    """
    if failed.is_valid():
        form = LoginForm()
        if form.validate_on_submit():
            user_verification = UserPasswordVerification(
                form.user.data, form.password.data)
            user.name = user_verification.user
            print(user_verification.verified)
            if user_verification.verified:
                user.pass_verified = True
                return redirect(url_for('main_page'))
            else:
                user.pass_verified = False
                failed.add()
        return render_template('password.html',
                               title="PasswordVerification",
                               form=form,
                               log=master_log)
    else:
        return redirect(url_for('block'))
コード例 #4
0
ファイル: user.py プロジェクト: Siacher/scrap-ticketsystem
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index.index'))
    else:
        form = LoginForm()
        if form.validate_on_submit():
            with db.connection.cursor() as cursor:
                sql = "SELECT * FROM user WHERE email=%s"
                cursor.execute(sql, (form.email.data, ))
                user = cursor.fetchone()

                if user is None:
                    flash('Invalid username or password')
                    print("no user")
                    return redirect(url_for('user.login'))

                if check_hash(form.passwort.data, user['password']):
                    user_login = LUser(user['id'], user['email'],
                                       user['first_name'], user['last_name'],
                                       user['password'])
                    login_user(user_login, remember=form.remember_me.data)
                    return redirect(url_for('index.index'))

                flash('Invalid username or password')
                print("wrong password")
                return redirect(url_for('user.login'))

    return render_template('login.html', form=form, login=True)
コード例 #5
0
ファイル: views.py プロジェクト: chanda1397/labtechApp
def login():
    form = LoginForm()
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    if request.args.get('error'):
        error = request.args.get('error')
    else:
        error = None
    if request.method == 'POST' and form.validate_on_submit():
        try:
            _id, password = int(form.student_id.data), form.password.data
        except ValueError:
            return redirect(url_for('auth.login', error = "Invalid User ID."))
        if not check_password(password):
            error = "Invalid Password."
        else:
            user = database.find_user_by_id(_id)
            if user:
                if user.validate_password(password):
                    login_user(user, remember=False)
                    return redirect(url_for("home"))
                else:
                    error = "Invalid Password."
            else:
                error = "User not Found."
    return render_template("login.html", form=form, error=error)
コード例 #6
0
def login():
    """
    Login
        Check for valid login information

    Parameters:
        N/A

    Returns:
        Rendered template html

    """
    #handles if someone types in this url when already logged in
    if current_user.is_authenticated:
        return redirect('/')

    current_form = LoginForm()

    if current_form.validate_on_submit():
        user = User.query.filter_by(
            username=current_form.username.data).first()
        if user is None or not user.check_password(current_form.password.data):
            flash('Invalid username or password')
            return redirect('/login')
        login_user(user, remember=current_form.remember_me.data)
        return redirect('/')
    return render_template('Login/login.html',
                           title='Sign In',
                           form=current_form)
コード例 #7
0
ファイル: app.py プロジェクト: DEV3L/flask-heroku-example
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('/index')
    return render_template('login.html', title='Sign In', form=form)
コード例 #8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            if request.args.get('next'):
                if "home" in request.args.get('next'):
                    return redirect(
                        url_for('file_and_folders',
                                next_url=request.args.get('next').replace(
                                    "/home", "")))
                else:
                    return redirect(url_for('upload_file'))
            else:
                return redirect(url_for('home'))
        else:
            flash("Login Unsuccessfull, Please check Username or Password",
                  "danger")
    return render_template("login.html",
                           title="File Server | LOGIN",
                           form=form,
                           allow_registractions=allow_registractions)
コード例 #9
0
ファイル: account.py プロジェクト: spchuang/community
def default_login():
   form = LoginForm()
   if form.validate_on_submit():
      user = User.query.filter_by(user_name = form.user_name.data).first()
      if user is not None and user.password == bcrypt.hashpw(form.password.data, user.password):
         login_user(user, remember = form.remember_me.data)   
         return redirect(request.args.get('next') or url_for('community_page.list'))
         
   return redirect(url_for('account.login'))
コード例 #10
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == "*****@*****.**" and form.password.data == "password":
            flash("You are logged in!", "success")
            return redirect(url_for("home"))
        else:
            flash("Login failed. Please check username and password.",
                  "danger")
    return render_template("login.html", title="Login", form=form)
コード例 #11
0
def log_in():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next = request.args.get('next')
            return redirect(url_for("home"))
    return render_template("log_in.html", form=form, title="Log in")
コード例 #12
0
def login():
  if current_user.is_authenticated:
    return redirect(url_for('home'))
  form = LoginForm()
  if form.validate_on_submit():
    user = User.query.filter_by(email=form.email.data).first()
    if user and bcrypt.check_password_hash(user.password, form.password.data):
      login_user(user, remember=form.remember.data)
      next_page = request.args.get('next')
      return redirect(next_page) if next_page else redirect(url_for('home'))
    else:
      flash('Login Unsuccessful. Please check email and password.','danger')
  return render_template('login.html', title='Login', form=form)
コード例 #13
0
ファイル: views.py プロジェクト: i404ed/MALBuilder
def login():
    """Get MAL user credentials and validate through MyAnimeList API"""
    if g.user and g.user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.rememberMe.data
        return after_login(MALB.authenticate(form.username.data, form.password.data))

    return render_template('login.html',
                           title='Sign In',
                           form=form)
コード例 #14
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        try:
            user = user_service.login_user(form.email.data, form.password.data)
            login_user(user, remember=form.remember.data)
            flash('You have been logged in!', 'success')
            # next_page = request.args.get('next')
            return redirect(url_for('index'))
        except (AttributeError, IntegrityError):
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
コード例 #15
0
def signin():
    if current_user.is_authenticated:
        return redirect(url_for('main.main'))

    form = LoginForm()
    if form.validate_on_submit():
        user = form.get_user()
        if user:
            login_user(user)
            return redirect(url_for('main.main'))
    else:
        flash_errors(form)
    return render_template("signin.html", form=form)
コード例 #16
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))

        # todo: add logging message after user login
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('index'))
    return render_template("login.html", title="Sign In", form=form)
コード例 #17
0
ファイル: views.py プロジェクト: yjsyyyjszf/dicom_read
    def post(self, request):
        form = LoginForm(request, data=request.POST)

        if form.is_valid():
            # Check where should the user be redirected
            next_redirect = request.POST.get('next', '')
            if not is_safe_url(url=next_redirect,
                               allowed_hosts=[request.get_host()]):
                next_redirect = reverse('/')

            auth_login(request, form.get_user())
            messages.info(request, 'Logged in as {}.'.format(request.user))
            return HttpResponseRedirect(next_redirect)

        return render(request, self.template, {'form': form})
コード例 #18
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
コード例 #19
0
def login():
    """
    Login request handler
    """
    if request.method == "GET":
        login_form = LoginForm()
        return render_template("login.html", login_form=login_form)

    elif request.method == "POST":
        login_form = LoginForm(request.form)
        if login_form.validate_on_submit():
            session.update(authenticated=True, username=login_form.email.data)
            return redirect(url_for("content.view"))
        else:
            return render_template("login.html", login_form=login_form)
コード例 #20
0
ファイル: routes.py プロジェクト: eolach/rxit_forms
def login():
    #     return redirect(url_for('index'))
    form = LoginForm()
    # if form.validate_on_submit():
    user = User.query.filter_by(username=form.username.data).first()
    app.logger.warning("logging here: " + user.username)
    if user is None or not user.check_password(form.password.data):
        app.logger.warning("Oops here: " + user.username)
        #     # return redirect(url_for('login'))
        return jsonify({
            "message": "incorrect password",
            "user": form.username.data,
            "password": form.password.data
            })
    login_user(user, remember=form.remember_me.data)
    app.logger.warning("logging here: " + current_user.username)
    #     return redirect(url_for(''))
    if (current_user.prescriber_id):
        user.prescriber = Prescriber.query \
            .filter_by(id=current_user.prescriber_id).first()
        user.dispenser = None
    elif (current_user.dispenser_id):
        user.dispenser = Dispenser.query \
            .filter_by(id=current_user.dispenser_id).first()
        user.prescriber = None
    else:
        return jsonify({
            "user": UserSchema().dump(current_user).data,
            "participantType": "superuser",
            "participantId": None,
            "participant": None

        })
    user_data = UserSchema().dump(user).data
    return jsonify(user_data)
コード例 #21
0
ファイル: routs.py プロジェクト: vipin3699/Test_Flask
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')[1:] if request.args.get(
                'next') else 'home'
            return redirect(url_for(next_page))
        else:
            flash("Login Unsuccessfull, Please check Username or Password",
                  "danger")
    return render_template("login.html", title="Flask | LOGIN", form=form)
コード例 #22
0
def login():
    form = LoginForm()
    if form.validate_on_submit():

        attempted_user = User.query.filter_by(
            username=form.username.data).first()

        if attempted_user and attempted_user.check_password_correction(
                attempted_password=form.password.data):
            login_user(attempted_user)
            flash(f"Success! you are logged in as {attempted_user.username}",
                  category='success')
            return redirect(url_for('market'))
        else:
            flash("Username and Password are not match please try again.",
                  category='danger')
    return render_template('login.html', form=form)
コード例 #23
0
    def get(self, request, error=False):
        """Рендеринг и вывод логин/пароль формы."""

        form = LoginForm()
        return render(request, 'login.html', {
            'form': form,
            'error': error,
        })
コード例 #24
0
def login():
    """
	Login route that authenticates a user with the database using hashed passwords.
	:return: render_template object
	"""
    if current_user.is_authenticated:
        return redirect(
            url_for('main_view.profile', username=current_user.username))
    form = LoginForm()
    if form.validate_on_submit():
        user = login_user_svc(email=form.email.data,
                              password=form.password.data)
        if not user:
            return abort(401, description="Incorrect username and password")
        login_user(user)
        return redirect(url_for('main_view.profile', username=user.username))
    return render_template('login.html', title='login', form=form)
コード例 #25
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            next_page = request.args.get('next')

            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Email or password are not valid!', 'unsuccess_field')

    return render_template('login.html', title='Login', form=form)
コード例 #26
0
def login():
    if current_user.is_authenticated:
        return redirect('/feed')
    form = LoginForm()
    if form.validate() and request.method == 'POST':
        user = get_user_by_username(form.username.data)
        if not user:
            return "<h1>This user doesn't exist</h1>"
        remember_me = form.remember_me.data
        if user.check_password(form.password.data) and user.is_active:
            from datetime import timedelta
            if login_user(user,
                          remember=remember_me,
                          duration=timedelta(days=1)):
                return redirect('/feed')
            else:
                return '<h1>unable to log you in</h1>'
    return render_template('login.html', form=form)
コード例 #27
0
def log_in(request):
    user_name = request.POST.get('username', None)
    pass_word = request.POST.get('password', None)
    print(user_name)
    print(pass_word)
    if user_name is None or pass_word is None:
        login_form = LoginForm()
        message = ""
    else:
        user = auth.authenticate(username=user_name, password=pass_word)
        if user is not None:
            print("user is not none")
            login(request, user)
            return redirect('src:home')
        else:
            message = 'نام کاربری یا رمز عبور اشتباه است!'
            login_form = LoginForm(request.POST)

    return render(request, "login.html", {
        'message': message,
        'login_form': login_form
    })
コード例 #28
0
def login_page(request):
    form = LoginForm(request.POST or None)
    print("User Logged in => ", request.user.is_authenticated)
    context = {
        "title": 'Form One',
        "content": 'Welcome to Login page',
        "form": form
    }
    if form.is_valid():
        print(form.cleaned_data)
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(request, username=username, password=password)
        print("User Logged in => ", request.user.is_authenticated)
        if user is not None:
            login(request, user)
            print("User Logged in => ", request.user.is_authenticated)
            context['form'] = LoginForm()
            return redirect('index')
        else:
            print("error in login")
            return redirect('login')
    return render(request, 'login.html', context)
コード例 #29
0
ファイル: app.py プロジェクト: curesh/KumbayUni
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        curr, conn = get_db_connection()
        uid = curr.execute("SELECT user_id FROM users WHERE username = (?)", [
            form.username.data,
        ]).fetchone()
        conn.close()
        if uid:
            uid = uid[0]
        user = load_user(uid)
        if not user or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(url_for('index'))

    return render_template('login.html', title='Sign In', form=form)
コード例 #30
0
def login():
    form = LoginForm()
    if request.method == "POST":
        if form.validate_on_submit():
            email, password = form.data["email"], form.data["password"]
            url = "{}/login".format(USER_MICROSERVICE_URL)
            current_app.logger.debug("URL to user microservice: {}".format(url))
            # Look at https://urllib3.readthedocs.io/en/latest/user-guide.html#certificate-verification
            user, status_code = UserService.login_user(email, password)
            # TODO improve the error code inside the User API
            if user is None and status_code != 404:
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="Connection refused",
                )

            if user is None and status_code == 404:
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="User not exist",
                )

            if UserService.log_in_user(user):
                return redirect("/")
            else:
                current_app.logger.error("log in failed")
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="An error occurred during log in. Please try later",
                )
    return render_template("login.html", _test="first_visit_login", form=form)
コード例 #31
0
def sign_up(request):
    form = LoginForm(request.POST)
    if form.is_valid():
        user = form.save()
        user.set_password(user.password)
        user.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('src:home')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'login_form': form})