def index(): if 'email' not in session: signup_form = SignupForm() signin_form = SigninForm() return render_template('home.html', signup_form=signup_form, signin_form=signin_form) user = db.session.query(User).filter_by(email=session['email']).first() if user is None: signup_form = SignupForm() signin_form = SigninForm() return render_template('home.html', signup_form=signup_form, signin_form=signin_form) projects = db.session.query(Project).filter_by(uid=user.uid).order_by( desc(Project.active)).all() items = db.session.query(Item).filter_by( uid=user.uid, state="Open").order_by(Item.opened_at).all() return render_template('index.html', projects=projects, user=user, items=items, message="")
def signin(): # f = open('/home/bill/glucose2-dev/glucose2-dev/wdt.log', 'w') # f.write(f'signin() {request.method}') # f.close() log('signin', f'{request.method}') if request.method == 'GET': flash(dbPath) form = SigninForm(request.form) jinjadict.update(dict(form=form)) log('signin', 'render_template(Signin.jinja2)') return render_template('Signin.jinja2', **jinjadict) else: form = SigninForm(request.form) jinjadict.update(dict(form=form)) typedcode = form.data['code'] log('signin', f'typedcode = {typedcode}') savedcode = System.getCode() log('signin', f'savedcode = {savedcode}') signedin = verify_password(savedcode, typedcode) Session.putSession('signedin', signedin) if signedin: # with db_session: # numberOfHeldReadings = len(Readings.select(lambda c: (c.am is not None and c.pm is not None) or c.hold is not None)) # log(f'signin: numberOfHeldReadings = {numberOfHeldReadings}') # jinjadict.update(dict(numberOfHeldReadings=numberOfHeldReadings)) rv = redirect(url_for('admin')) log('signin', 'redirect(url_for("admin"))') return rv else: flash('Try Again') return redirect(url_for('signin'))
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)
def login(): form = SigninForm() if form.validate_on_submit(): flash('{} is logged in'.format(form.email.data)) return redirect( '/home') # url_for('home')) # can use return redirect('/login') return render_template('login.html', title='Sign in', form=form)
def signin(request): if request.method == 'GET': return render(request, 'front_signin.html') else: form = SigninForm(request.POST) if form.is_valid(): email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user = login(request, email, password) if user: remember = form.cleaned_data.get('remember') if remember: request.session.set_expiry(None) else: request.session.set_expiry(0) # 跳转到 nexturl = request.GET.get('next') if nexturl: return redirect(nexturl) else: return redirect(reverse('front_index')) else: return render(request, 'front_signin.html', {"error": u'用户名和密码错误'}) else: return render(request, 'front_signin.html', {'error': form.get_error()})
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)
def signup(): if request.method == 'POST': signup_form = SignupForm() signin_form = SigninForm() if signup_form.validate() == False: return render_template('home.html', signin_form=signin_form, signup_form=signup_form) else: joined = datetime.datetime.now() newuser = User(signup_form.firstname.data, signup_form.lastname.data, signup_form.email.data, signup_form.password.data, joined) db.session.add(newuser) db.session.commit() # Uncomment to send confirmation email # subject = "Confirm your email" # token = security.ts.dumps(newuser.email, salt='email-confirm-key') # confirm_url = url_for( # 'confirm_email', # token=token, # _external=True) # html = "Your account was successfully created. Please click the link below to confirm\ # your email address and activate your account:{confirm_url}".format(confirm_url=confirm_url) # security.send_email(subject, newuser.firstname, newuser.email, html) session['email'] = newuser.email return redirect(url_for('index')) elif request.method == 'GET': return redirect(url_for('index'))
def facebook_authorized(resp): if resp is None: return 'Access denied: reason=%s error=%s' % ( request.args['error_reason'], request.args['error_description']) session['oauth_token'] = (resp['access_token'], '') me = facebook.get('/me') if checkEmail(me.data['email']) == False: url = "http://graph.facebook.com/" + me.data['location']['id'] result = urllib2.urlopen(url).read() result = json.loads(result) addUser(me.data['id'], me.data['username'], me.data['email'], 'abcde', me.data['location']['name'], resp['access_token'], "facebook", str(result['location']['longitude']), str(result['location']['latitude'])) session['email'] = me.data['email'] return redirect(url_for('profile')) else: if userType(me.data['email']) == "facebook": session['email'] = me.data['email'] return redirect(url_for('profile')) else: form = SigninForm() form.email.errors = ["Wrong Account Type"] return render_template('signin.html', form=form)
def reset(): form = EmailForm() if request.method == 'POST': if form.validate() == False: return render_template('reset.html', form=form) else: user = User.query.filter_by( email=form.email.data.lower()).first_or_404() if user: subject = "Password reset requested" token = security.ts.dumps(user.email, salt='recover-key') recover_url = url_for('reset_with_token', token=token, _external=True) html = "Click <a href={}> here </a> to change your password".format( recover_url) security.send_email(subject, user.firstname, user.email, html) signup_form = SignupForm() signin_form = SigninForm() message = "Reset email sent to {}".format(user.email) return render_template('home.html', signup_form=signup_form, signin_form=signin_form, message=message) else: return "That user does not exist" elif request.method == 'GET': return render_template('reset.html', form=form)
def signin(): if 'account_name' 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: user_name = form.user_name.data password = form.user_password.data user = household_account.query.filter_by( account_name=user_name).first() if user is not None and user.check_password(password): session['account_name'] = form.user_name.data return redirect(url_for('home')) else: return redirect(url_for('signin')) elif request.method == "GET": return render_template("signin.html", form=form) return render_template("signin.html")
def login(): if session.get('logged_in'): if session['logged_in'] is True: return redirect(url_for('home', title="Sign In")) form = SigninForm() if form.validate_on_submit(): """checks database to see if username exists""" existing_user = mongo.db.users.find_one( {"username": request.form.get("username").lower()}) if existing_user: """checks hashed password to ensure match with user input""" if check_password_hash(existing_user["password"], request.form.get("password")): session["user"] = request.form.get("username").lower() session['logged_in'] = True flash("Welcome, {}".format(request.form.get("username"))) return redirect(url_for("home", username=session["user"])) else: """in case where password does not match""" flash("Incorrect Username and/or Password") return redirect(url_for("login", form=form)) else: """in case where username does not exist""" flash("Incorrect Username and/or Password") return redirect(url_for("login", form=form)) return render_template("login.html", form=form)
def signin(): if current_user.is_authenticated: return redirect(url_for('index')) sform = SigninForm() try: if sform.validate_on_submit(): user = Users.query.filter_by(username=sform.username.data).first() if user: if bcrypt.check_password_hash(user.password, sform.password.data): login_user(user, remember=sform.remember.data) flash('Your have successfully logged in', 'success') return redirect(url_for('index')) else: flash('Invalid Password! Please try again', 'danger') return redirect(url_for('signin')) else: flash('Invalid Username! Please try again...', 'danger') return redirect(url_for('signin')) except: flash( 'Oops! Something wrong with the Database.Please try again after some time.' ) return redirect(url_for('signin')) return render_template('user/signin.html', form=sform)
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'))
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"
def signin(): form = SigninForm() if form.validate_on_submit(): session['email'] = form.email.data person = Person.query.filter_by(email=session['email']).first() name = person.firstname flash('You are logged in') return redirect(url_for('dashboard', name=name)) return render_template('signin.html', form=form)
def signin(request): if request.method == "POST": form = SigninForm(request.POST) # username = req.POST["username"] # password = req.POST["password"] username = form["username"].value() password = form["password"].value() user = authenticate(request, username=username, password=password) if user is not None: login(request, user) messages.success(request, "Successfully logged in") return redirect("shop:home") else: messages.error(request, "Invalid Username or Password") else: form = SigninForm() context = {"form": form} return render(request, "shop/signin.html", context)
def signin(): form = SigninForm() 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_me.data) return redirect(url_for('homepage', nickname=current_user.username)) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('signIn.html', title="SignIn", form=form)
def handle_register(): signin_form = SigninForm() register_form = RegisterForm() if 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('2form2view.html', signin_form=signin_form, register_form=register_form)
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)
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)
def render_home_view(self, signup_form=SignupForm(auto_id=True), signin_form=SigninForm(auto_id=True), active_auth_index=0): # otherwise show home view: context = { 'signup_form': signup_form, 'signin_form': signin_form, 'active_auth_index': active_auth_index, } context.update(csrf(self.request)) return render(self.request, 'dashboard/home.html', context)
def register(): #error = None lform = SignupForm(request.form, prefix="SignupForm") #print(request.form) if request.method == 'POST': if lform.validate() == False: return render_template('index.html', lform=lform, rform=SigninForm()) else: return "register"
def login(): form = SigninForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is not None and user.check_password(form.password.data): login_user(user, form.remember_me.data) flash('Logged in successfully') return redirect( request.args.get('next') or url_for('main.index', username=user.username)) flash('Invalid username or password.') return render_template('login.html', form=form)
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('')
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = SigninForm() if form.validate_on_submit(): session['remember_me'] = form.remember_me.data return oid.try_login(app.config['GOOGLE_OPENID'], ask_for=['nickname', 'email']) return render_template( 'signin.html', title='Sign In', form=form, )
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)
def signin(request): context = {} context['form'] = SigninForm() if request.method == 'POST': form = SigninForm(request.POST) context['form'] == form if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: auth_user = authenticate(username=username, password=password) login(request, auth_user) return redirect('/countrylist/') except Exception, e: return HttpResponse( 'Wrong USERNAME or PASSWORD! Please <a href="/signin/">Try Again </a>' )
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)
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)
def signin(): form = SigninForm() redir = redirect_already_authenticateds(current_user) if redir: return redirect(url_for(redir)) redir = process_forms_and_redir(form) if redir: return redirect(url_for(redir)) else: return set_template('panelbuilder.html', form, '.signin', panel_args=dict( patex=current_app.config['PAHDS']['signin'], tadata=current_app.config['TADATA']['signin']))