Пример #1
0
def login():
    """Login Route

        This route leads to the login page.

        Args:
            None

        Returns:
            if GET returns the rendered login page
            if POST returns a validated user redirected to the
                non-public index page

        Raises:
            redirects back to login if login not valid
    """
    form = SignInForm()

    if current_user.is_authenticated:
        return redirect(url_for('auth.logged_in'))

    if 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('auth.login'))
            login_user(user, remember=form.remember_me.data)
            return redirect(url_for('main.index'))
    return render_template('login.html', title='CONP | Log In', form=form, error=form.errors)
Пример #2
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('books'))
    signinform = SignInForm()
    signupform = SignUpForm()
    if signinform.validate_on_submit():
        user = User.query.filter_by(username=signinform.username.data).first()
        password = make_secure_token(signinform.password.data)
        if user is not None and password == user.password:
            login_user(user)
            return redirect(url_for('books'))
        else:
            flash('Invalid login. Please try again.')
    if signupform.validate_on_submit():
        username = signupform.username.data
        email = signupform.email.data
        password = make_secure_token(signupform.password.data)
        user = User(username=username, email=email, password=password)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('books'))
    return render_template('auth.html',
                           title='Sign In',
                           signinform=signinform,
                           signupform=signupform, )
Пример #3
0
def login_user(request):
    error=False
    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            raw_password = form.cleaned_data["password"]
            user = authenticate(username=username, password=raw_password)
            if user:
                login(request,user)
                groupe = User.objects.filter(groups__name='client', id=user.id) #On cherche si notre utilisateur est un client
                if not groupe: #Si aucun objet n'est retourné, il n'est pas client
                    estClient = False
                else:           #Sinon, c'est un client
                    estClient =True
                request.session['estClient'] = estClient #On mémorise cette information
                request = init_panier(request)
                request = init_reservation(request) #On initiliase le panier et le panier_reservation de l'utilisateur

                if estClient:
                    return redirect('homepage')
                else:
                    return redirect('gestion/dashboard/')
            else:
                error=True
                #ErrorMessage = "Username ou mot de passe incorrect"
    else:
        form= SignInForm()
    return render(request, 'signin.html', locals())
Пример #4
0
def signin():
    form = SignInForm()
    if form.validate_on_submit():
        e_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=e_password)
        db.session.add(user)
        db.session.commit()
        msg = "Created user {}".format(form.name.data)
        flash(msg, "success")
    return render_template("SignInForm.html", message="Register", form=form)
Пример #5
0
def signin():
    form = SignInForm()
    if form.validate_on_submit():
        student_id = form.student_id.data
        try:
            at_sign_in(student_id, column=DATE_COLUMN)
            flash(f"Okay, I'll sign in user {student_id}")
            with open('scans.csv', 'a') as f:
                f.write(f"{datetime.datetime.now()},{student_id},-,-\n")
            return redirect(url_for('signin'))
        except:
            flash('No such user!')
            return redirect(url_for('register', student_id=student_id))
    return render_template('signinform.html', form=form)
Пример #6
0
def sign_in(request):
    form = SignInForm()

    if request.method == "POST":
        form = SignInForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect("/")

    return render(request, 'sign_in.html', locals())
Пример #7
0
def login():
    error = None
    form = SignInForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        user = User.query.filter_by(username=username).first()
        if password == user.password:
            login_user(user, remember=True)

            run_watching()
            return redirect(url_for('index'))
    return render_template('signin.html', form=form, error=error)
Пример #8
0
def sign_in_post():
    form = SignInForm()
    details = "OK"
    if form.validate():
        res = SignIn().sign_in(form.login.data, form.password.data)
        answer = res['answer']
        details = res['details']
        if answer == True:
            session['signed_user'] = res['username']
            session['registration_ended'] = res['registration_ended']
            User().set_online(session['signed_user'])
    else:
        answer = False
        details = "Form Error"
    return json.dumps({"answer": answer, "details": details})
Пример #9
0
def login():
    error = None
    form = SignInForm()

    if current_user.is_authenticated:
        return redirect(url_for('logged_in'))

    if 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('login'))
            login_user(user, remember=form.remember_me.data)
            return redirect(url_for('index'))
    return render_template('login.html', title='CONP | Log In', form=form, error=form.errors)
Пример #10
0
def sign_in():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = SignInForm(request.form)

    if form.validate_on_submit():
        user = models.User.query.filter_by(
            user_email=form.user_email.data).first()
        if not user or not user.check_user_pw(form.user_password.data):
            flash('Invalid User ID or Password.')
            return redirect(url_for('sign_in'))
        login_user(user, remember=form.user_remember_me.data)
        return redirect(url_for('index'))

    return render_template('signIn.html', form=form)
Пример #11
0
def search():
    signin = SignInForm()
    signup = SignUpForm()
    return render_template('search.html',
                           title='Search',
                           signin=signin,
                           signup=signup)
Пример #12
0
def public():
    signin = SignInForm()
    signup = SignUpForm()
    return render_template('public.html',
                           title='Home',
                           signin=signin,
                           signup=signup)
Пример #13
0
def login():
	title = "Login"
	if current_user.is_authenticated:
		return redirect(url_for('index'))
	form = SignInForm()
	if form.validate_on_submit():
		user = User(dict = users_col.find({"username":form.username.data})[0])
		if user is None or not user.check_password(form.password.data):
			flash('Invalid username or password')
			return redirect(url_for('index'))
		login_user(user)
		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', form=form)
Пример #14
0
    def post(self):
        form = SignInForm(request.form)

        if form.validate():
            account = form.account

            if not account.profile:
                flash("You need to complete your profile first.", 'danger')
            elif not account.team:
                flash("You're not on a team!", 'danger')
            else:
                try:
                    sign_in_email(account.email, account.team.teamID,
                                  account.team.domPass)
                    account.signin = datetime.datetime.now
                    account.save()
                    flash("Welcome, %s!" % (account.email), 'success')
                except:
                    flash(
                        "There's been an issue sending your email. Go find Andrew!",
                        'danger')

            return redirect(url_for('sign_in'))

        return self.render_template(form=form)
Пример #15
0
def signIn():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    signInForm = SignInForm()
    if signInForm.validate_on_submit():
        user = User.query.filter_by(email=signInForm.email.data).first()
        if user is None or not user.check_password(signInForm.password.data):
            flash('Invalid email or password', 'danger')
            return render_template('sign_in.html',
                                   title='Sign In',
                                   form=signInForm)
        login_user(user, remember=signInForm.remember_me.data)
        return redirect(url_for('game'))
    else:
        return render_template('sign_in.html',
                               title='Sign In',
                               form=signInForm)
Пример #16
0
def login_page():
    form = SignInForm()  # object class obtained from the app.forms module
    # this contains the field defnitions (booleans, string & pw fields)
    # it is passed into the render_template, which expects these definitions

    # to handle user data being submitted (this function does the heavy lifting):
    if form.validate_on_submit():
        # the validate_on_submit method won't trigger during the initial GET request
        # from the browser to fetch the html of the page, hence this check
        # or if any of the field validations (e.g. pw) fails. Can add error message later
        flash("Login requested for user {}, remember_me={}".format(
            form.username.data, form.remember_login.data
        ))  # Flask method, flash shows a message to the user. Needs html (see base.html)
        # the login doesn't do anything yet, besides confirm data is recieved
        return redirect(url_for('game'))  # sends user somewhere else
    # the url_for calls the corresponding page handling function rather than the path directly
    return render_template("login.html", form=form, title="Login to Game")
Пример #17
0
def sign_in():
    if current_user.is_authenticated:
        return redirect(url_for("dashboard"))

    form = SignInForm(request.form)

    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", "danger")
            return redirect(url_for("sign_in"))

        login_user(user, remember=form.remember_me.data)
        flash(f"User {current_user.username} logged in successful", "success")
        return redirect(url_for("dashboard"))

    return render_template("sign_in.html", title="Sign in page", form=form)
Пример #18
0
def sign_in():
    """Login page view"""
    if current_user.is_authenticated:
        return redirect(url_for('profile', user_id=current_user.id))
    form = SignInForm()
    # if form.validate_on_submit():
    #     return redirect(request.args.get('next') or
    #                     url_for('profile', user_id=current_user.id))
    return render_template('sign_in.html', form=form)
Пример #19
0
def index():
    form = SignInForm()

    #IF USER CONNECTED REDIRECT TO DASHBOARD
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    #SEND FROM IF CONDITIONS = OK AND REDIRECTS
    if request.method == 'POST' and form.validate_on_submit():

        #VERIFY IF USER EXIST IN DATABASE
        user = User.query.filter_by(username=form.username.data).first()

        #IF USER OR PASSWORD DONT MATCH RETURN TO LOGIN
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('index'))

        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('dashboard'))

    return render_template('signin.html', title='Sign In', form=form)
Пример #20
0
def sign_in():
    # Redirect the user to the index page if he or she has been authenticated
    # already.
    if current_user.is_authenticated:
        return redirect(url_for('home.home'))

    form = SignInForm(request.form)

    if form.validate_on_submit():
        user = form.validate_signin()

        if user:
            # Notify the login manager that the user has been signed in.
            login_user(user)
            if user.disabled:
                flash(_('Your account has been disabled, you are not allowed '
                        'to log in'), 'danger')
            else:
                flash(_('Hey %(name)s, you\'re now logged in!',
                        name=current_user.first_name), 'success')

            referer = request.headers.get('Referer')
            denied = (
                re.match(r'(?:https?://[^/]+)%s$' % (url_for('user.sign_in')),
                         referer) is not None)
            denied_from = session.get('denied_from')

            if not denied:
                if referer:
                    return redirect(referer)
            elif denied_from:
                return redirect(denied_from)

            return redirect(url_for('home.home'))

    if form.errors:
        flash_form_errors(form)

    return render_template('user/sign_in.htm', form=form)
Пример #21
0
def signup():
    form_sign_up = SignInForm()
    if current_user.is_authenticated:
        return redirect('/')

    if utils.find_user_by_username(form_sign_up.username.data):
        flash('That username is taken, please try again.')
        return render_template('signup.html',
                               title='Sign Up',
                               form=form_sign_up)

    if form_sign_up.password.data != form_sign_up.password2.data:
        flash("Your passwords didn't match, please try again.")
        return render_template('signup.html',
                               title='Sign Up',
                               form=form_sign_up)

    if form_sign_up.validate_on_submit(
    ) and form_sign_up.password.data == form_sign_up.password2.data:
        db.create_all()
        loc = models.Location.query.filter_by(
            city=form_sign_up.city.data,
            region=form_sign_up.region.data).first()
        if not loc:
            loc = models.Location(city=form_sign_up.city.data,
                                  region=form_sign_up.region.data,
                                  country='placeholder')
            db.session.add(loc)
            db.session.commit()

        user = models.User(username=form_sign_up.username.data,
                           location_id=loc.id)
        user.set_password(form_sign_up.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect('/login/')

    return render_template('signup.html', title='Sign Up', form=form_sign_up)
Пример #22
0
def login_view(request):
    next = request.GET.get('next')
    # subdomain = request.META['HTTP_HOST'].split('.')[0]
    # try:
    #     org = Organization.objects.get(slug=subdomain)
    # except (Organization.DoesNotExist, Organization.MultipleObjectsReturned) as e:
    #     raise Http404
    form = SignInForm()
    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            user = authenticate(email=email, password=password)
            if user is not None:
                login(request, user)
                if user.name == '':
                    messages.add_message(request, messages.SUCCESS, _('Please update your profile'))
                    return redirect('settings')
                else:
                    messages.add_message(request, messages.SUCCESS, _('Your have signed in successfully'))
                    return redirect('/app/')
    return render(request, 'app/login.html', locals())
Пример #23
0
    def post(self, request):
        if request.user.is_authenticated:
            return HttpResponseRedirect(reverse('main'))

        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return HttpResponseRedirect(
                request.POST.get('next') or reverse('main'))
        else:
            form = SignInForm()
            return render(request, 'login.html', {
                'form': form,
                'unauthorized': True
            })
Пример #24
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('logged_in'))
    signin = SignInForm()
    signup = SignUpForm()

    #if request.method == 'POST' and form.validate():
    #    if load_user(form.username.data) is None:
    #        flash('Invalid username')
    #    else:
    #        if check_password_hash(cred.password, form.password.data):
    #            return redirect(url_for('browse'))
    #       else:
    #            flash('Invalid password')
    #return render_template('login.html', title='Login', form=form)

    return render_template('login.html', title='Log in', signin=signin, signup=signup)
Пример #25
0
 def get_form(self):
     return SignInForm()
Пример #26
0
    def get(self, request):
        if request.user.is_authenticated:
            return HttpResponseRedirect(reverse('main'))

        form = SignInForm()
        return render(request, 'login.html', {'form': form})
Пример #27
0
def sign_in():
    form = SignInForm()
    return render_template('sign_in.html', title='Sign In', form=form)