def resetpassword(token): print(token) if request.method == "POST": print('post') form = ResetPasswordForm() if form.validate_on_submit(): new_password = request.form.get("password") email = confirm_token(token) user = User.query.filter_by(email=email).first_or_404() print('first or 404') if user.password == new_password: flash('Type another password', 'error') return render_template('resetpassword.html', form=form) user.password = new_password db.session.commit() flash('Now you changed your Password', 'success') return redirect(url_for('login')) else: print(form.errors) return render_template('resetpassword.html', form=form) try: email = confirm_token(token) print(email) if email: user = User.query.filter_by(email=email).first_or_404() print(user) form = ResetPasswordForm() return render_template('resetpassword.html', form=form) except: pass abort(404)
def login(): # print('admin ttt') # if current_user.is_authenticated.user_lvl == 'admin': # print('admin 222') # return redirect(url_for('admin')) # print('adminn 444') # elif current_user.is_authenticated.user_lvl == 'editor': # return redirect(url_for('submitarticle')) # elif current_user.is_authenticated.user_lvl == 'reviewer': # return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): print("vali") user = User.query.filter_by(email=form.email.data).first() if user is None: flash('Email is invalid', 'error') return redirect(url_for('login')) if user.password != form.password.data: flash('Password is invalid', 'error') return redirect(url_for('login')) if not user.confirmed: flash('Please confirm email before login', 'warning') return redirect(url_for('login')) login_user(user, remember=form.remember.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) print(form.errors) return render_template('login.html', title='Sign In errorr', form=form, errors=form.errors)
def submitarticle(): form = PapersForm() if request.method == 'GET' and (int(current_user.user_lvl) == 10 or int(current_user.user_lvl) == 100): return render_template("submitarticle.html", form=form) #return redirect(url_for('index')) if form.validate_on_submit(): f = form.body.data filename = secure_filename(f.filename) f.save('uploads/' + filename) file_url = "uploads/" + filename print(file_url) p = Paper(title=form.title.data, user_id=current_user.id, abstract=form.abstract.data, keyword=form.keyword.data, body=file_url, reference=form.reference.data, created_time=datetime.now(), updated_time=datetime.now(), paper_status='new') db.session.add(p) db.session.commit() else: print(form.errors) file_url = None return render_template('index.html', form=form)
def login(): form = LogInForm() if request.method == 'GET': return render_template('login.html', form=form) elif request.method == 'POST': if form.validate_on_submit(): try: conn = mysql.connect() cursor = conn.cursor() cursor.callproc('ValidateLogin', (form.email.data, )) rv = cursor.fetchall() finally: conn.commit() conn.close() print len(rv) if len(rv) != 0: if check_password_hash(str(rv[0][2]), form.password.data): voter = Voter(rv[0][0], rv[0][1]) login_user(voter) return redirect(url_for('showAGMs')) else: return "Wrong password" else: return "user doesn't exist" else: return "form not validated" else: return "form not validated"
def contact(): #Validation form = ContactForm() if form.validate_on_submit(): name = form.name.data email = form.email.data message = form.message.data mailing = form.mailing.data #Flask-Mail msg = Message("Website Contact Form Message From " + form.name.data, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """ From: %s Email: %s Message: %s Mailing: %s """ % (form.name.data, form.email.data, form.message.data, form.mailing.data) mail.send(msg) flash("Message sent!") #Add to database with sqlite3.connect(app.config['DATABASE']) as con: cur = con.cursor() cur.execute( "INSERT INTO contact (name, email, message, mailing) VALUES (?,?,?,?)", (name, email, message, mailing)) con.commit() return render_template('contact.html', banner="static/img/slider_4.jpg", title='Contact', contact=form)
def verify(): form = ConfirmForm() data = form.input.data if form.validate_on_submit(): if '@' in data: user = get_user(email=data) if user: if user.confirmed_email != 'true': return redirect( url_for('send_confirmation_email', email=data, _external=True)) flash('User already verified', 'error') return redirect(url_for('profile', username=user.username)) flash('User does not exist, please register', 'error') return redirect(url_for('verify')) else: user = get_user(phone=data) if user: if user.confirmed_phone != 'true': return redirect( url_for('send_confirmation_link', phone=data, _external=True)) flash('User already verified', 'error') return redirect(url_for('profile', username=user.username)) flash('User does not exist, please register', 'error') return redirect(url_for('verify')) return render_template('verify.html', form=form)
def recover_we(): form = Recovery() if request.method == 'POST': user = get_user(email=form.user_email.data) if form.validate_on_submit(): if user: if user.confirmed_email == 'true': email = form.user_email.data msg = Message('Password Reset', sender='*****@*****.**', recipients=[email]) key = 'Admin111' #generaterandom admin key...key = randomKey() msg.body = "Click this admin key {} to reset your password".format( key) msg.html = render_template('mail/recovery.html', user=user, link=key) mail.send(msg) flash('Email Sent, check your inbox and follow the steps', 'success') return redirect(url_for('login')) flash( "Your email is not confirmed, please confirm to continue", 'error') return redirect(url_for('verify')) flash('Email not recognized', 'error') return redirect(url_for('recover_we')) flash('Validation Email not recognized', 'error') return redirect(url_for('recover_we')) return render_template('forgot-e.html', form=form)
def post(): form = PostForm() src = [{'filetype': 'None', 'path': 'None'}] privacy = request.form['privacy'] if request.method == 'POST': if 'media' in request.files: media = request.files.getlist('media') process = upload(media, privacy=privacy, used_as='post') if process['result'] == 'done': path = process['path'] type_ = process['filetype'] postname = process['postname'] src = [{'path': path, 'filetype': type_, 'filename': postname}] pass if form.validate_on_submit(): new_post = Posts(post_content={ 'headline': form.headline.data, 'body': form.body.data, 'media': src }, privacy=privacy, timestamp=getDate()) db.session.add(new_post) db.session.commit() flash("Post successfull!", "success") return redirect(url_for('home')) return redirect(url_for("home")) abort(400)
def login(): form = LoginForm() if form.validate_on_submit(): # login and validate the user... login_user(user) flash("Logged in successfully.") return redirect(request.args.get("next") or url_for("index")) return render_template("login.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) return render_template('auth/login.html', form=form)
def forgotpassword_template(): form = ForgotForm(request.form) if form.validate_on_submit(): msg = Message('Reset your password with the link below: ', recipients=[form.email]) mail.send(msg) return render_template("forgotpassword_template.html", name=session.get('name'), username=session.get('username'), form=form)
def register(): form = forms.RegisterForm() if form.validate_on_submit(): flash("Yay, you registered!", "success") models.User.create_user( username=form.username.data, email=form.email.data, password=form.password.data ) return redirect(url_for('index')) return render_template('register.html', form=form)
def add(): form = PostForm() if form.validate_on_submit(): post_data = Posts(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post_data) db.session.commit() return redirect(url_for('home')) else: return render_template('post.html', title='Add a Post', form=form)
def post_update(update): form = UpdatePostDetails() postupdate = Posts.query.filter_by(id=update).first() if form.validate_on_submit(): postupdate.title = form.title.data postupdate.content = form.content.data db.session.commit() return redirect(url_for('home')) elif request.method == 'GET': form.title.data = postupdate.title form.content.data = postupdate.content return render_template('postedit.html', title='Edit Post', form=form)
def reset_request(): if current_user.is_authenticated: return redirect(url_for('home')) form = RequestResetForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() send_reset_email(user) flash('An mail has been sent to your email.', 'info') return redirect(url_for('login')) return render_template('reset_request.html', title='Reset Password', form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.first_name = form.first_name.data current_user.last_name = form.last_name.data current_user.email = form.email.data db.session.commit() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form)
def login(): form = LoginForm() if current_user.is_authenticated: return redirect(url_for('sessions.profile')) if form.validate_on_submit(): user = User.get(email=form.email.data) if user: if check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) return redirect(url_for('sessions.profile')) return render_template('sessions/login.html', form=form) return render_template('sessions/login.html', form=form)
def register_view(): form = RegistrationForm(request.form) if form.validate_on_submit(): user = Admin() form.populate_obj(user) db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.login_view')) link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>' return render_template('register.html', form=form, login=link)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post ahs been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def createproject_template(): form = Project(request.form) print(form.errors) if form.validate_on_submit(): with open('data/projects.csv', 'a') as f: writer = csv.writer(f) writer.writerow( [form.name, form.challenge, form.description, form.file]) flash('Project Submitted!') return render_template("createproject_response_template.html", form=form, name=session.get('name'), username=session.get('username')) return render_template("createproject_template.html", form=form)
def login(): form = forms.LoginForm() if form.validate_on_submit(): try: user = models.User.get(models.User.email == form.email.data) except models.DoesNotExist: flash("Your email or password doesn't match!", "error") else: if check_password_hash(user.password, form.password.data): login_user(user) flash("You've been logged in!", "success") return redirect(url_for('index')) else: flash("Your email or password doesn't match!", "error") return render_template('login.html', form=form)
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() print("Token:", token) flash("You can now login") flash('A confirmation email has been sent to you by email.') return redirect(url_for("main.index")) return render_template("auth/register.html", form=form)
def login_view(): form = LoginForm(request.form) print 'here' if form.validate_on_submit(): user = Admin() form.populate_obj(user) # populates obj attributes with form data db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.admin_index')) link = '<p>Don\'t have an account? <a href="' + url_for('.register_view') + '">Click here to register.</a></p>' return render_template('login.html', form=form, register=link)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = Users.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') if next_page: return redirect(next_page) else: return redirect(url_for('home')) return render_template('login.html', title='Login', form=form)
def register_view(): form = RegistrationForm(request.form) if form.validate_on_submit(): user = Admin() form.populate_obj(user) db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.login_view')) link = '<p>Already have an account? <a href="' + url_for( '.login_view') + '">Click here to log in.</a></p>' return render_template('register.html', form=form, login=link)
def login_view(): form = LoginForm(request.form) print 'here' if form.validate_on_submit(): user = Admin() form.populate_obj(user) # populates obj attributes with form data db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.admin_index')) link = '<p>Don\'t have an account? <a href="' + url_for( '.register_view') + '">Click here to register.</a></p>' return render_template('login.html', form=form, register=link)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): data = Organisation.query.all() if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(country=form.country.data, email=form.email.data, firstname=form.firstname.data, lastname=form.lastname.data, username=form.username.data, org_id=form.organizationid.data, phone=form.phone.data, sciencedegree=form.sciencedegree.data, user_lvl=1, confirmed=False, password=form.password.data, usfield=form.usfieldsname.data) if form.organizationid.data not in Organisation.query.all(): new_org = Organisation(name=form.organizationid.data, country=form.country.data) db.session.add(new_org) db.session.commit() if form.usfieldsname.data not in Field.query.all(): new_field = Field(name=form.usfieldsname.data) db.session.add(new_field) db.session.commit() db.session.add(user) db.session.commit() flash( 'Congratulations, you are now a registered user! Check Email to confirm account', 'success') token = generate_confirmation_token(form.email.data) s = request.host_url + "confirm/" + token st, msg = Send_EMAIL( form.email.data, f"Congratulations, you are now a registered user! confirm account {s}", title='Register your account on Al-Khorezmi') return redirect(url_for('login')) print(form.errors) return render_template('register.html', form=form, data=data)
def change_details(): form = ResetForm() if request.method == 'POST': user = current_user password = user.password if form.validate_on_submit(): if check_password_hash(password, form.old_password.data): user.password = generate_password_hash(form.new_password.data, method='sha256') db.session.add(user) db.session.commit() flash("Your password has been succesfully updated", 'success') return redirect(url_for('admin_page', username=user.username)) flash("password's don't match", 'error') return redirect(url_for('change_details')) return redirect(url_for('change_details')) return render_template("change-details.html")
def login_view(self): form = AdminLoginForm() if form.validate_on_submit(): admin = mongo.db.admins.find_one({'email': form.email.data}) if admin is not None and check_password_hash( admin['password'], form.password.data): admin = Customer(admin['email']) login_user(admin, form.remember_me.data) return redirect(request.args.get('next') \ or url_for('.index')) else: flash('Admin account required.') form.email.data = '' form.password.data = '' return self.render('admin/login.html', form=form) flash('Invalid admin email or password.') return self.render('admin/login.html', form=form)
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def createproject_template(): form = Project(request.form) print(form.errors) if form.validate_on_submit(): with open( '../../PycharmProjects/SOEN287_A3_40021696_ELIESABBAGH/data/match.csv', 'a') as f: writer = csv.writer(f) writer.writerow([ form.name.data, form.matchChoices, form.description.data, form.file.data ]) flash('Project Submitted!') return render_template("createproject_response_template.html", form=form, name=session.get('name'), username=session.get('username')) return render_template("createproject_template.html", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hash_pw = bcrypt.generate_password_hash(form.password.data) user = Users(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=hash_pw) db.session.add(user) db.session.commit() return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def login(): print('login called') #print(url_for('api.add', _external=True)) form = LoginForm() pprint(form) if form.validate_on_submit(): user = User.by_email(form.email.data) if user is not None and user.password == form.password.data: login_user(user, remember=True) flash("Logged in successfully.") print("Logged in successfully.") if request.args.get('jsonify', "true") == "false": rsp = redirect(url_for('ui.home')) else: rsp = make_response(jsonify(success=True, output="Successfully logged in.")) return rsp else: if request.args.get('jsonify', "true") == "false": return redirect(url_for('ui.login_view')) else: return jsonify(success=False, output="Bad password.", callback="/feeds/login")