def POST(self): post = web.input(_method='POST') # Validate user = users.get_user_by_name(post['username']) if user is not None: response = {'message': 'false'} else: auth = 1 if post['authority'] == 'guest' else 0 user = users.add(username=post['username'], password=users.pswd(post['password']), authority=auth) response = {'message': 'true'} logs.add_user(post['username']) return json.dumps(response)
def POST(self): post = web.input(_method='POST') user = users.get_user_by_name(post['username']) if user is None: response = {'message': 'nonexist'} elif user['password'] != users.pswd(post['password']): response = {'message': 'nomatch'} elif user['authority'] == 1: response = {'message': 'nopermission'} else: users.login(user) response = {'message': 'success'} logs.login(post['username']) return json.dumps(response)
def login(): valid_login = True if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = users.get_user_by_name(username) if user: valid_password = common.check_password(password, user['password']) if valid_password: session['username'] = username session['user_id'] = user['id'] return redirect(url_for('index')) if not valid_password: valid_login = False if not user: valid_login = False return render_template("login.html", valid_login=valid_login)
def post(self): formentries = {'username':"", 'err_username':"", 'err_password':"", 'err_verify':"", 'email':"", 'err_email':"" } username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') username_match = valid_username(username) password_match = valid_password(password) email_match = valid_email(email) verify_match = False if password_match: verify_match = (password == verify) if username_match and password_match and verify_match and (email == "" or email_match): ## Form is well if users.get_user_by_name(username): formentries['username'] = username formentries['email'] = email; formentries['err_username']="******" self.write_signup_form(**formentries) else: user = users.put_user(username,password,email) user_id_cookie = utils.make_secure_val(str(user.key().id())) self.response.headers.add_header('Set-Cookie',str('user_id=%s; Path=/' % user_id_cookie)) self.redirect("/") else: formentries['username']=username formentries['email']=email if username_match == None: formentries['err_username']="******" if password_match == None: formentries['err_password']="******" elif verify_match == False: formentries['err_verify']="Your passwords didn't match." if email and email_match == None: formentries['err_email'] = "That's not a valid email." self.write_signup_form(**formentries)