def isThereThisEmail(email): data = dict() if UserModel.isThereThisEmail(email): data["result"] = True else: data["result"] = False return json.dumps(data)
def emailVerify(): if request.method == "GET": email = request.args.get("email") hashCode = request.args.get("hash") if email != None and UserModel.isThereThisEmail(email) and hashCode != None: if hashCode == generateEmailVerificationHashCode(email): UserModel.verifyEmail(email) flash("Your email address verified successfully!", "success") return redirect(url_for("login")) return redirect(url_for("index"))
def passwordReset(): if request.method == "POST": email = request.form.get("email") hashCodeFromUser = request.form.get("hash") password = request.form.get("password") confirmPassword = request.form.get("confirm-password") if email != None and UserModel.isThereThisEmail(email): hashCode = generatePasswordResetHashCode(email) if hashCodeFromUser != None and password != None and confirmPassword != None: if hashCode == hashCodeFromUser and password == confirmPassword: #Get user id userId = UserModel.getUserByEmail(email)["uid"] #Update password UserModel.updatePassword(userId, password) flash("Your password updated succesfully. Now you can log in.", "success") return redirect(url_for("login")) else: #Send password reset mail sendMail({ "To" : email, "Subject" : "Password Reset - devSeater", "Body" : render_template("mail/password-reset-mail.html", SITE_ADDR = SITE_ADDR, email = email, hashCode = hashCode) }) #Show message flash("If you have entered your email address properly, we sent you an email. Please check your inbox.", "success") else: return redirect(url_for("index")) return redirect(url_for("passwordReset")) else: email = request.args.get("email") hashCode = request.args.get("hash") return render_template("intro/password-reset.html", email = email, hashCode = hashCode)
def index(): if not isLoggedIn(): if request.method == "POST": # USER REGISTRATION email = request.form.get("email").strip() name = request.form.get("name").strip() username = request.form.get("username").strip() password = request.form.get("password").strip() terms = request.form.get("terms") #Validate all values errorMessages = dict() if (not isValidEmail(email)): errorMessages["email"] = "Please enter a valid email address" elif (UserModel.isThereThisEmail(email)): errorMessages["email"] = "This email address is already taken" if (len(name) < 3): errorMessages["name"] = "Name should be at least 3 characters" if (not isValidUsername(username)): errorMessages[ "username"] = "******" elif (UserModel.isThereThisUsername(username)): errorMessages["username"] = "******" if not isValidPassword(password): errorMessages[ "password"] = "******" if (terms != "on"): errorMessages["terms"] = "You should accept terms" if (not errorMessages): UserModel.addUser({ "email": email, "username": username, "full_name": name, "password": password }) sendVerificationEmail(email) flash( "User created successfully, please check your inbox for email verification", "success") return redirect(url_for("login")) else: return render_template("intro/intro.html", form=request.form, errorMessages=errorMessages) else: return render_template("intro/intro.html") else: #Logged In #Get User Projects userProjects = ProjectModel.getUserProjects(session["uid"]) lastFollowingPosts = UserPostModel.getLastFollowingPosts( session["uid"], 10) popularProjects = ProjectModel.getPopularProjects(10) whoToFollowList = UserModel.getWhoToFollowList(5, getCurrentUid()) #Get Current User Informations currentUser = UserModel.getUser(session["uid"]) return render_template("index.html", userProjects=userProjects, popularProjects=popularProjects, lastFollowingPosts=lastFollowingPosts, currentUser=currentUser, whoToFollowList=whoToFollowList)