def verifyUser(verify_uuid): try: User.verify(verify_uuid) # If no exceptions happen, redirect them to the login page with success flash('You have successfully verified your email. You may now log in.', 'success') return redirect('/login?type=user') except UserException: # This means we didn't find the verification abort(404) except Exception: # This means an error happened, most probably something SQL abort(500)
def donate(): if 'isLoggedIn' in session: if request.method == 'POST': try: User.addItem(request.form, session, request.files) flash('Item added successfully.', 'success') return redirect('/items') except UserException as ue: flash(ue.reason, 'error') return redirect('/addItem') else: return render_template('addItem.html', orgs_details=Organization.getAllVerified()) else: flash('You are not logged in yet! Please login then try again.', 'error') return redirect('/login?type=user')
def login(): if not 'isLoggedIn' in session: if request.method == 'POST': if request.form.get('type') == 'user': try: data = User.login(request.form) session['isLoggedIn'] = data session['type'] = 'user' if data[13]: return redirect('/admin') else: return redirect('/dashboard') except UserException as ue: flash(ue.reason, 'error') return redirect('/login?type=user') elif request.form.get('type') == 'org': try: data = Organization.login(request.form) session['isLoggedIn'] = data session['type'] = 'org' return redirect('/dashboard') except OrgException as ue: flash(ue.reason, 'error') return redirect('/login?type=org') else: abort(400) else: return render_template('login.html', type=request.args.get('type')) else: return redirect('/dashboard')
def changePwd(): if 'isLoggedIn' in session: if session['type'] == 'user': try: User.changePassword(request.form, session) flash('Successfully changed password.', 'success') return redirect('/userProfile') except UserException as ue: flash(ue.reason, 'error') return redirect('/userProfile') else: try: Organization.changePassword(request.form, session) flash('Successfully changed password.', 'success') return redirect('/orgProfile') except OrgException as oe: flash(oe.reason, 'error') return redirect('/orgProfile') else: flash('You must be logged in to do that!', 'error') return redirect('/login')
def accept(uuid): if 'isLoggedIn' in session: if session['type'] == 'user': try: User.accept(uuid) flash('Pickup time accepted! You will be contacted by the organization shortly.', 'success') return redirect('/items') except UserException as ue: flash(ue.reason, 'error') return redirect('/items') else: try: Organization.acceptItem(uuid) flash('Pickup time accepted! Please contact the donator for further details.', 'success') return redirect('/items') except OrgException as ue: flash(ue.reason, 'error') return redirect('/items') else: flash('You are not logged in yet! Please login then try again', 'error') return redirect('/login')
def changePickupTime(uuid): if 'isLoggedIn' in session: if session['type'] == 'user': try: User.changePickupTime(request.form, uuid) flash('Pickup time changed successfully.', 'success') return redirect('/items') except UserException as ue: flash(ue.reason, 'error') return redirect('/items') else: try: Organization.changePickupTime(request.form, uuid) flash('Pickup time changed successfully.', 'success') return redirect('/items') except OrgException as ue: flash(ue.reason, 'error') return redirect('/items') else: flash('You are not logged in yet! Please login then try again', 'error') return redirect('/login')
def removeItem(uuid): if 'isLoggedIn' in session: if session['type'] == 'user': try: User.removeItem(uuid) flash('Item removed successfully', 'success') return redirect('/items') except UserException as ue: flash(ue.reason, 'error') return redirect('/items') else: try: Organization.removeItem(uuid) flash('Item removed successfully', 'success') return redirect('/items') except OrgException as ue: flash(ue.reason, 'error') return redirect('/items') else: flash('You are not logged in yet! Please login then try again', 'error') return redirect('/login')
def register(): if request.method == 'POST': if request.form.get('type') == 'user': try: User.insert(request.form) flash('You have successfully registered. Please click the link in your email to verify your account and get access.', 'success') return redirect('/login?type=user') except UserException as ue: flash(ue.reason, 'error') return redirect('/register?type=user') elif request.form.get('type') == 'org': try: Organization.insert(request.form, request.files) flash('You have successfully registered. Please click the link in your email to verify your account and get access.', 'success') return redirect('/login?type=org') except OrgException as ue: flash(ue.reason, 'error') return redirect('/register?type=org') else: abort(400) else: return render_template('register.html', type=request.args.get('type'))
def editInfo(): if 'isLoggedIn' in session: if session['type'] == 'user': try: session['isLoggedIn'] = User.editInformation(request.form, session) flash('Successfully changed information.', 'success') return redirect('/userProfile') except UserException as ue: flash(ue.reason, 'error') return redirect('/userProfile') else: flash('You must be logged in to do that!', 'error') return redirect('/login')
def viewUser(uuid): if 'isLoggedIn' in session: if session['type'] == 'org': # Fetch user info user_info = User.fetchByUUID(uuid) if user_info is not False: return render_template('viewUser.html', userData=user_info) else: abort(404) else: abort(404) else: flash('You are not logged in yet! Please login then try again.', 'error') return redirect('/login?type=org')
def items(): if 'isLoggedIn' in session: if session['type'] == 'user': try: items = User.getAllItems(session['isLoggedIn'][1]) return render_template('itemsUser.html', items_list=items) except UserException as ue: flash(ue.reason, 'error') return redirect('/dashboard') else: try: items = Organization.getAllItems(session['isLoggedIn'][1]) return render_template('itemsOrg.html', items_list=items) except OrgException as ue: flash(ue.reason, 'error') return redirect('/dashboard') else: flash('You are not logged in yet! Please login then try again', 'error') return redirect('/login')