def post(self): user_username = self.request.get("username") user_password = self.request.get("password") user_verify = self.request.get("verify") user_email = self.request.get("email") uname = user_username email = user_email uname_err = utils.check_username(user_username) pw_err="" vpw_err="" email_err="" Success= True if uname_err != "": Success= False if utils.check_password(user_password)==False: pw_err="That's not a valid password." Success= False if utils.verify_password(user_password, user_verify)==False: vpw_err="Your passwords didn't match." Success= False if len(email) != 0: if utils.check_email(user_email)==False: email_err="That's not a valid email." Success= False if Success: x = utils.make_pw_hash(uname, user_password) saltedPass = x.split("|")[0] salt = x.split("|")[1] if len(email) != 0: newUser = User(key_name = uname, username = uname, email=email, password = saltedPass, salt = salt) else: newUser = User(key_name = uname, username = uname, password = saltedPass, salt = salt) newUser.put() setUser = "******" + uname self.response.headers.add_header('Set-Cookie', setUser.encode()) self.redirect("/") else: self.render_signup(uname, email,uname_err, pw_err, vpw_err,email_err)
def post(self, wiki_url): # url = wiki_url wiki = self.request.get("content") u = self.request.cookies.get("user", "") if u == "": self.redirect("/login" + wiki_url) else: logged_user = User.get_by_key_name(u) if wiki: wp = WikiPage(key_name=wiki_url, wiki_url=wiki_url, wiki_page=wiki, user_edit=logged_user) wp.put() memCacheWiki(wiki_url=wiki_url, update=True) self.redirect(wiki_url)
def create_user(): if request.mimetype != 'application/json': raise Exception('Content-Type is not "application/json".') j = request.get_json() Sesson, engine = dbconnect(db_options) session = Sesson() user = User(first_name=j.get('first_name'), last_name=j.get('last_name'), username=j.get('username'), school_id=get_or_create_school(session, j.get('school')), email=j.get('email')) session.add(user) session.flush() session.commit() return jsonify({'id': user.id})
def register(): # If the user is logged in, don't let them register if 'user' in g and g.user.is_authenticated(): return redirect(url_for('secured_area')) from lib.forms.registration_form import RegistrationForm form = RegistrationForm() if form.validate_on_submit(): log.debug("valid form, registering user") # Create a new user user = User(email=form.email.data, password=form.password.data) db.session.add(user) db.session.commit() login_user(user) flash("Logged in successfully.", 'success') return redirect(request.args.get("next") or url_for("secured_area")) return render_template('register.html', form=form)