def post(self): loggedIn = False username = self.request.get('username') password = self.request.get('password') use = User.all().filter('username', username) if use.count() == 1: #user found user = use.get() if (user.password == password): i = uuid.uuid1() sess = Session(user=user.username, sessId=str(i)) sess.put() self.session['sessId'] = str(i) loggedIn = True template_params = {'loggedIn': loggedIn, 'user': user.username} render_template(self, 'login.html', template_params) else: #no user found/something went wrong loginError = True template_params = { 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self, 'login.html', template_params) else: #no user found/something went wrong loginError = True template_params = { 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self, 'login.html', template_params)
def post(self): loggedIn= False username=self.request.headers.get('Username') password=self.request.headers.get('Password') print("username="******"password="******"match") i = uuid.uuid1() sess = Session(user=user.username,sessId=str(i)) sess.put() self.response.headers['Content-Type'] = 'application/json' obj = { 'sessKey':str(i) } self.response.out.write(json.dumps(obj)) else: #no user found/something went wrong print("badpass") else: print("badname")
def post(self): loggedIn= False username=self.request.get('username') password=self.request.get('password') use = User.all().filter('username',username) if use.count() == 1: #user found user = use.get() if(user.password == password): i = uuid.uuid1() sess = Session(user=user.username,sessId=str(i)) sess.put() self.session['sessId']=str(i) loggedIn = True template_params={'loggedIn':loggedIn, 'user': user.username} render_template(self,'login.html',template_params) else: #no user found/something went wrong loginError = True template_params={ 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self,'login.html',template_params) else: #no user found/something went wrong loginError = True template_params={ 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self,'login.html',template_params)
def post(self): loggedIn = True username = self.request.get('username') password = self.request.get('password') android = self.request.get('android') use = User.all().filter('username', username) self.session.delete(username)
def post(self): loggedIn= True username=self.request.get('username') password=self.request.get('password') android=self.request.get('android') use = User.all().filter('username',username) self.session.delete(username)
def admin_users(request): """ 增加一个路由 /admin/users 只有 id 为 1 的用户可以访问这个页面, 其他用户访问会定向到 /login 这个页面显示了所有的用户 包括 id username password """ body = template('admin_users.html', user_list=User.all()) return http_response(body)
def getuser(self): if self.session.get('sessId'): i = str(self.session.get('sessId')) sess = Session.all().filter('sessId',i).get() user = User.all().filter('username',sess.user).get() return user else: return None
def post(self): user = self.getuser() if (user is not None): #check if user has permission to add target user to jirga #user can add if owner of private jirga #user can add if adding self to public jirga targetJirga = self.request.get('jirga') targetJ = Jirga.all().filter('jirgaId', targetJirga).get() if (targetJ is not None): #jirga was found targetUser = self.request.get('user') targetU = User.all().filter('username', targetUser).get() if targetU is not None and targetU.key( ) not in targetJ.members: print(targetU.key) #user was found if (targetJ.publicJirga == 0) and (targetJ.owner == user.username): #private jirga but user owns it flag = True for key in targetU.jirgas: if key == targetJ.key: print(key() + " - " + targetJ.key()) flag = False if flag: targetU.jirgas.append(targetJ.key()) targetJ.members.append(targetU.key()) targetJ.put() targetU.put() #todo get rid of these time.sleeps start having better data routes time.sleep(1) self.redirect("/jirgaSettings/" + targetJ.jirgaId) elif (targetJ.publicJirga == 1) and (targetU.username == user.username): #public jirga, user is adding self user.jirgas.append(targetJ.key()) targetJ.members.append(targetU.key()) user.put() targetJ.put() time.sleep(1) self.redirect("/jirgaSettings/" + targetJ.jirgaId) else: #insufficient permissions self.response.write("FAIL - insufficient permissions") else: #user was not found self.redirect("/jirgaSettings/" + targetJ.jirgaId) else: #jirga was found self.response.write("FAIL - invalid jirga") else: self.response.write("FAIL - not logged in")
def user_register(request, all_user=''): if request.method == 'POST': form = request.form() u = User.new(form) if u.validate_register(): result = '注册成功<br>' all_user = User.all() else: result = '用户名或者密码长度必须大于2' else: result = '' body = template('register.html', result=result, all_user=all_user) return http_response(body)
def post(self): loggedIn= False username=self.request.get('username') password=self.request.get('password') android=self.request.get('android') use = User.all().filter('username',username) if use.count() == 1: #user found user = use.get() if(user.password == password): i = uuid.uuid1() sess = Session(user=user.username,sessId=str(i)) sess.put() self.session['sessId']=str(i) badPass = False loggedIn = True template_params={'loggedIn':loggedIn, 'user': user.username} render_template(self,'login.html',template_params) else: #no user found/something went wrong loginError = True template_params={ 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self,'login.html',template_params) if android is not None and (android)==1: if(badPass): self.response.write("FAIL-BADPASS") if(loginError): self.response.write("FAIL-LOGINERROR") else: self.response.write("OK") else: self.redirect("/") else: if android is not None and (android)==1: self.response.write("FAIL-BADNAME") else: #no user found/something went wrong loginError = True template_params={ 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self,'login.html',template_params)
def post(self): loggedIn = False username = self.request.get('username') password = self.request.get('password') android = self.request.get('android') use = User.all().filter('username', username) if use.count() == 1: #user found user = use.get() if (user.password == password): i = uuid.uuid1() sess = Session(user=user.username, sessId=str(i)) sess.put() self.session['sessId'] = str(i) badPass = False loggedIn = True template_params = {'loggedIn': loggedIn, 'user': user.username} render_template(self, 'login.html', template_params) else: #no user found/something went wrong loginError = True template_params = { 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self, 'login.html', template_params) if android is not None and (android) == 1: if (badPass): self.response.write("FAIL-BADPASS") if (loginError): self.response.write("FAIL-LOGINERROR") else: self.response.write("OK") else: self.redirect("/") else: if android is not None and (android) == 1: self.response.write("FAIL-BADNAME") else: #no user found/something went wrong loginError = True template_params = { 'loggedIn': loggedIn, 'loginError': loginError, } render_template(self, 'login.html', template_params)
def get(self,sessId): sess = Session.all().filter('sessId',sessId).get() if sess is not None: user = User.all().filter('username',sess.user).get() print("user" + user.username) if(user is not None): jirgas = Jirga.get(user.jirgas) result = [] self.response.headers['Content-Type'] = 'application/json' for jirga in jirgas: obj2 = { 'name': jirga.title, 'key': jirga.jirgaId, } result.append(obj2) print(jirga.title) self.response.out.write(json.dumps(result)) else: self.response.write("FAIL - not logged in")
def get(self, sessId): sess = Session.all().filter('sessId', sessId).get() if sess is not None: user = User.all().filter('username', sess.user).get() print("user" + user.username) if (user is not None): jirgas = Jirga.get(user.jirgas) result = [] self.response.headers['Content-Type'] = 'application/json' for jirga in jirgas: obj2 = { 'name': jirga.title, 'key': jirga.jirgaId, } result.append(obj2) print(jirga.title) self.response.out.write(json.dumps(result)) else: self.response.write("FAIL - not logged in")
def post(self): success = False template_params = {} username = self.request.get('username') password = self.request.get('password') android = self.request.get('android') use = User.all().filter('username', username) if use.count() == 0: #no collisions nameTaken = False if (password is not None) and (password != ""): #valid password badPass = False #create user account usernew = User(username=username, password=password) usernew.put() success = True template_params = {'success': success} else: #invalid password badPass = True template_params = {'success': success, 'badPass': badPass} if android is not None and (android) == 1: if (badPass): self.response.write("FAIL-BADPASS") else: self.response.write("OK") else: render_template(self, 'createUser.html', template_params) else: if android is not None and (android) == 1: self.response.write("FAIL-BADNAME") else: #username taken nameTaken = True template_params = {'success': success, 'nameTaken': nameTaken} render_template(self, 'createUser.html', template_params)
def post(self): success = False template_params={} username=self.request.get('username') password=self.request.get('password') android=self.request.get('android') use = User.all().filter('username',username) if use.count() == 0: #no collisions nameTaken = False if (password is not None) and (password != ""): #valid password badPass = False #create user account usernew = User(username=username,password=password) usernew.put() success=True template_params={'success':success} else: #invalid password badPass = True template_params={'success':success,'badPass':badPass} if android is not None and (android)==1: if(badPass): self.response.write("FAIL-BADPASS") else: self.response.write("OK") else: render_template(self,'createUser.html',template_params) else: if android is not None and (android)==1: self.response.write("FAIL-BADNAME") else: #username taken nameTaken = True template_params={'success':success,'nameTaken':nameTaken} render_template(self,'createUser.html',template_params)