def newuser(): error = None app.logger.debug('in new user') if request.method == 'POST': app.logger.debug('past first if') userid = request.form['userid'] password = request.form['password'] confirmPass = request.form['confirmPass'] app.logger.debug('past form requests') email = request.form['email'] app.logger.debug('past form requests') boolError = isValidNewUser(userid, password, confirmPass, email) if boolError[0]: app.logger.debug('valid info') user = User(request.form['userid'], request.form['password'], request.form['email']) dao = UserDao() dao.insert(user) return redirect(url_for('findtextbooks')) else: error = boolError[1] app.logger.debug('about to render newuser.html') app.logger.debug('error %r', error) return render_template('newuser.html', error=error)
def new(): error = None #Wapp.logger.debug("password1" in request.form) if (request.method == 'POST'): if request.form['submitnew'] == 'submit': if request.form['userid1'] is not None and request.form[ 'password1'] is not None: if nottaken(request.form['userid1'], request.form['password1']): userid = request.form['userid1'] password = request.form['password1'] em = request.form['emailaddress'] pic = request.form.get('pic') dao = UserDao() us = User(userid, password, em, pic, '') dao.insert(us) return redirect(url_for('login')) else: return render_template('new.html', error=error) # the code below is executed if the request method # was GET or the credentials were invalid elif (request.method == 'GET'): return render_template('new.html', error=error)
def createAccount (): # Locals: error = None dao = UserDao () background = decode (session ['background']) es = EmailService () if (request.method == 'POST'): row = dict (userid=request.form['userid'], password=request.form['password'], emailaddr=request.form['emailaddr']) temp = dao.rowToUser (row) if (dao.isAvailable (temp)): dao.insert (temp) if (es.sendSignupEmail (temp)): print ('INFO:\t[Borb.createAccount()]\tCreated Account: ' + str (row)) redirect (url_for ('login')) else: print ('Error sending account creation email. Must be invalid email addess. EMAIL ADDRESS: ' + row.get('emailaddr')) error = 'It appears you have entered an invalid email adress. Please try again.' else: error = 'Darn! That account appears to have already been taken' print ('INFO:\t[Borb.createAccount()]\tCould not create account.') return render_template ('createaccount.html', **locals ())
def isValidRecepient(userid): dao = UserDao() user = dao.selectByUserId(userid) if (user is not None) and (userid == user.userid): return True else: return False
def login(): error = None if ('submit' in request.form) and ('userid' in request.form) and ('password' in request.form): userid = request.form['userid'] if isValid(request.form['userid'], request.form['password']): session['userid'] = request.form['userid'] return inbox() else: error = 'Invalid userid/password' elif ('submit2' in request.form) and (request.form['passwordNew'] is not None) and (request.form['useridNew'] is not None): if not (isValid(request.form['useridNew'], request.form['passwordNew'])): dao = UserDao() #insert into datbase dao.insertNew(request.form['useridNew'], request.form['passwordNew']) #create datbase files for user f = open((str(request.form['useridNew']) + "emails.db"), "w+") f = open((str(request.form['useridNew']) + "outbox.db"), "w+") f = open((str(request.form['useridNew']) + "trash.db"), "w+") session['userid'] = request.form['useridNew'] ResetDB(str(request.form['useridNew'])) session.clear() f.close() return redirect(url_for('login')) return render_template('login.html', error=error)
def isValidNewUser(userid, password, confirmPass, email): app.logger.debug('in isValidNewUser of newuser') dao = UserDao() users = dao.selectAll() for user in users: app.logger.debug('checking user: %r', user.userid) if user.userid == userid: app.logger.debug("username already taken") error = 'Username already taken' app.logger.debug('error %r', error) return [False, error] if len(userid) < 3: error = 'Username must have at least 3 characters' return [False, error] elif len(password) < 6: error = 'Password must have at least 6 characters' return [False, error] elif password != confirmPass: error = 'Entered passwords must match' return [False, error] elif email == "" or email is None or '@' not in email: error = 'Please Enter Valid Email Address' return [False, error] error = None return [True, error]
def nottaken(userid, password): #app.logger.debug(userid) dao = UserDao() #app.logger.debug(userid) use = dao.selectByUserid(userid) if use is None: return True else: return False
def isValidCreate(userid, password1, password2): dao = UserDao() user = dao.selectByUserId(userid) if (user is not None): return 3 elif (password1 != password2): return 2 else: return 1
def isValid(userid, password): dao = UserDao() user = dao.selectByUserId(userid) if (user is not None) and (userid == user.userid) and (password == user.password): session['user'] = encode(user) return True else: return False
def groupsearch(): userid = session['userid'] userdao = UserDao() user = userdao.selectByUserid(userid) allg = GroupDao() groups = allg.selectAll() if (request.method == 'POST'): return render_template('groupsearchresults.html', **locals()) elif (request.method == 'GET'): return render_template('groupsearchresults.html', **locals())
def isValid(self, userid, password): dao = UserDao() user = dao.selectByUserId(userid) if user is not None: if (user.password == password): # logger.debug('isvalid is true') return True else: # logger.debug('is valid is false') return False
def isValidUpload(title, author, subject, course, condition, price): dao = UserDao() users = dao.selectAll() if title is None or title == '' or author is None or author == '' or subject is None or subject == '' or condition is None or condition == '' or price is None or price == '': error = 'Field left empty' return [False, error] error = None return [True, error]
def events(): userid = session['userid'] userdao = UserDao() user = userdao.selectByUserid(userid) dao = EventDao() dao.expire() events = dao.selectAll() if (request.method == 'POST'): return render_template('events.html', **locals()) elif (request.method == 'GET'): return render_template('events.html', **locals())
def isValid(userid, password): dao = UserDao() user = dao.selectByUserId(userid) if (user is None): return 3 elif (user.password != password): return 2 else: session['userid'] = user.userid session['mail'] = None session['reply'] = None return 1
def isValid(userid, password): dao = UserDao() user = dao.selectByUserid(userid) if (user is not None) and (userid == user.userid) and (password == user.password): session['user'] = encode( user ) # use an encoder to convert user to a JSON object for session return True else: return False
def isValidLogin(userid, password): app.logger.debug('in isValidNewUser of login') app.logger.debug('userid of isValidNewUser login: %r', userid) app.logger.debug('password of isValidNewUser login: %r', password) dao = UserDao() user = dao.selectByUserid(userid) if (user is not None) and (userid == user.userid) and (sha256_crypt.verify( password, user.password)): session['user'] = encode( user ) # use an encoder to convert user to a JSON object for session return True else: return False
def accountrecovery (): error = None dao = UserDao () es = EmailService () background = decode (session['background']) if (request.method == 'POST'): if (dao.isValidPair (request.form['userid'], request.form['emailaddr'])): es.recoverPassword (request.form['userid']) return redirect (url_for ('login')) else: error = 'Hmm... We don\'t seem to have an account with those credentials.' # This will display if the credentials were bad OR the call was a GET request. (ie. First time accessing the page.) return render_template ('recoveraccount.html', **locals ())
def create(): error = None userid = session['userid'] userdao = UserDao() user = userdao.selectByUserid(userid) if (request.method == 'POST'): if (request.form["submitnewgroup"] == "Create Group"): name = request.form['name'] if (not taken(name)): us = UserDao() us.addMember(session['userid'], name) descr = request.form['description'] mess = request.form['mess'] gdao = GroupDao() newg = Group(name, descr, session['userid']) gdao.insert(newg) mdao = MessageDao(name) m = Message(session['userid'], mess, user.profPic) mdao.insert(m) return redirect(url_for('home')) else: return render_template('creategroup.html', **locals()) elif (request.method == 'GET'): return render_template('creategroup.html', **locals())
def NewUser(): error = None if('Register' in request.form): if (request.form['newpassword']==request.form['verifypassword']): if not isValid(request.form['newuserid'],request.form['newpassword']): dao = UserDao() dao.insertNew(request.form['newuserid'],request.form['newpassword']) return redirect(url_for('login')) else: error=1 return render_template('NewUser1.html',error=error) else: error=2 return render_template('NewUser1.html',error=error) if('Login' in request.form): return redirect(url_for('login')) # the code below is executed if the request method # was GET or the credentials were invalid return render_template('NewUser1.html', error=error)
def home(): dao = UserDao() user = dao.selectByUserid(session['userid']) groups = dao.returnUserList(user.userid) gdao = GroupDao() gro = [] for group in groups: gro.append(gdao.selectByName(group)) if (request.method == 'POST'): if ("view" in request.form): session["grouptoview"] = request.form['view'] return redirect(url_for("view")) else: return render_template('home.html', **locals()) elif (request.method == 'GET'): return render_template('home.html', **locals())
def NewUser(): dao=UserDao() error = None #print("Here") if('Register' in request.form): user=dao.selectByUserid(request.form['newuserid']) print(user) if (request.form['newpassword']==request.form['verifypassword']): if (user is None) and (request.form['newuserid'] != user): dao.insertNew(request.form['newuserid'],request.form['newpassword']) return redirect(url_for('login')) else: #passwords do not match error=1 return render_template('NewUser1.html',error=error) elif (user is not None) and (request.form['newuserid'] != user.userid): #Username is already taken error=2 return render_template('NewUser1.html',error=error) if('Login' in request.form): return redirect(url_for('login')) return render_template('NewUser1.html', error=error)
def isValid(userid, password): dao = UserDao() user = dao.selectByUserid(userid) if (user is not None) and (userid == user.userid) and (password == user.password): now=datetime.datetime.now() session['printM']=now.month if (len(str(session['printM']))<2): session['printM']=str(str(session['printM']).zfill(2)) session['printD']=now.day if (len(str(session['printD']))<2): session['printD']=str(str(session['printD']).zfill(2)) session['printY']=now.year if (len(str(session['printY']))<2): session['printY']=str(session['printY']).zfill(2) date=session['printM']+"-"+str(session['printD'])+"-"+str(session['printY']) session['currentdate']=date # print("DATE:"+viewdate) session['user']=encode(userid) # use an encoder to convert user to a JSON object for session return True else: return False
def login (): error = None dao = UserDao () backgroundIndex = str (random.randint (1, 9)) while (decode (session['background']) == backgroundIndex): backgroundIndex = str (random.randint (1, 9)) session['background'] = encode (backgroundIndex) #print ('INFO:\t[Borb.login()]\tGenerated background with index:\t' + backgroundIndex) if (request.method == 'POST'): if (dao.isValid (request.form['userid'], request.form['password'])): session['userid'] = encode (request.form['userid']) return redirect (url_for ('cheepeats')) else: error = 'Woops! We don\'t seem to have an account with those credentials.' #error = dao.selectByUserId (request.form['userid']).password # This will display if the credentials were bad OR the call was a GET request. (ie. First time accessing the page.) return render_template ('login.html', **locals ())
def isValidUser(userid): dao = UserDao() user = dao.selectByUserId(userid) if (user is None): return False return True
def view(): error = None userid = session['userid'] userdao = UserDao() user = userdao.selectByUserid(userid) gdao = GroupDao() gname = session['grouptoview'] tgname = gname groupname = gdao.selectByName(gname) daomess = MessageDao(gname) messages = daomess.selectAll() messages.reverse() data = messages if (request.method == 'POST'): if (request.form["submitnewmessage"] == "Add New Message"): m = Message(session['userid'], request.form["textvalue"], user.profPic) daomess.insert(m) messages = daomess.selectAll() return redirect(url_for("view")) elif (request.form["submitnewmessage"] == "Add New User"): app.logger.debug("HERe") uta = request.form["newUser"] if (not nottaken2(uta)): ouserdao = UserDao() ouserdao.addMember(uta, gname) gdao.addMember(gname, uta) return redirect(url_for("view")) else: return redirect(url_for("view")) elif (request.form["submitnewmessage"] == "Create Event"): eventname = request.form["eventname"] eventdes = request.form["eventdescription"] eventstart = request.form["starttime"] eventend = request.form["endtime"] tempst = eventstart.split("T") tempen = eventend.split("T") datest = tempst[0] dateen = tempst[0] tempdayst = datest.split("-") yearst = tempdayst[0] monthst = tempdayst[1] dayst = tempdayst[2] tempdayen = dateen.split("-") yearen = tempdayen[0] monthen = tempdayen[1] dayen = tempdayen[2] timest = tempst[1] timeen = tempen[1] newEvent = Event(dayst, monthst, yearst, dayen, monthen, yearen, timest, timeen, eventname, eventdes, gname, "") dao = EventDao() dao.insertEvent(newEvent) return redirect(url_for("view")) else: return redirect(url_for("view")) elif (request.method == 'GET'): return render_template('view.html', **locals())
import uuid from userdao import UserDao from user import User from random import randint user_dao = UserDao() class UserService: def __init__(self): pass @classmethod def login(cls, username, password): users = None if username[0] == 'C': users = user_dao.get_all_customers(username, password) elif username[0] == 'M': users = user_dao.get_all_managers(username, password) if users is not None: for user in users: if user.get_username() == username and user.get_password( ) == password: return user return None @classmethod def register(cls, username, password, email): # ensure this user hasn't already registered error = None new_user = None
from taskdao import TaskDao from userdao import UserDao from task import Task from user import User import os #os.remove('users.db') dao = UserDao() #dao.populate() users = dao.selectAll() for user in users: print(user.toString()) #os.remove('task.db') dao = TaskDao() #dao.populate() tasks = dao.selectAll() for task in tasks: print(task.toString())
def createAccount(userid, password): user = User(userid, password) dao = UserDao() dao.insert(user)
def cheepeats (): userid = decode(session ['userid']) # We can't allow access to this page without having you log in first. if decode (session['userid']) is None: print ('ERROR:\t[Borb.cheepeats()]\tAttempted to access maps page without signing in. Redirecting to login screen...') return redirect (url_for ('login')) dao = UserDao () nest = dao.accessUserNest (userid) insertIntoNest = request.args.get ('insert') removeFromNest = request.args.get ('remove') updateNest = request.args.get ('update') # # Request from Front End to UPDATE Client-side collection of places. # if (updateNest != None): print ('INFO:\t\tNest UPDATE request received.') nest = dao.accessUserNest (userid) nestCollection = {} for nestItem in nest: nestCollection[str (nest.index (nestItem))] = dao.nestItemToRow (nestItem) return jsonify (dict (containsElements=any(nestCollection),places=nestCollection, imgURL=url_for ('static', filename='img/close_button.png'))) # # Request from Front End to add item to user-nest.db: # if (insertIntoNest != None): print ('INFO:\t\tNest INSERT request received.') queryParams = (insertIntoNest.split ('&')) # Separate and format the Parameters: for param in queryParams: index = queryParams.index (param) queryParams[index] = param.split ('=')[1] # Clean the paramters: for c in range (0, len (queryParams)): queryParams[c] = urllib.parse.unquote (queryParams[c]) queryParams[c] = str.replace (queryParams[c], '+', ' ') insertIntoNest = dict(name=queryParams[0], location=queryParams[1], address=queryParams[2], place_id=queryParams[3]) success = dao.insertNestItem (insertIntoNest) insertRequest = jsonify (dict (status=success, nestItem=insertIntoNest, imgURL=url_for ('static', filename='img/close_button.png'))) return insertRequest #TODO: if (removeFromNest != None): print ('INFO:\t\tNest REMOVE request received.') nest = dao.accessUserNest (userid) print (nest) toBeRemoved = dao.selectByPlaceId (removeFromNest) dao.removeNestItem (toBeRemoved) return jsonify (toBeRemoved) return render_template ('cheepeats.html', **locals ())
def update_user(): conn = pool.get_connection() dao = UserDao(conn) user = request.get_json() dao.update_user(user)
def get_user(user_id): conn = pool.get_connection() dao = UserDao(conn) user = dao.get_user(user_id) return json.dumps(user)
from emaildao import EmailDao from emails import Email from userdao import UserDao from user import User import os import logging from flask import Flask from flask import session #repopulates users os.remove('users.db') dao = UserDao() dao.populate() users = dao.selectAll() for user in users: print(user.toString())
import pickledb from userdao import UserDao uDao = UserDao () uDao.populate () print ('INFO:\tData Store Population complete.')