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 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 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 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 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 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 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())