def userPhoto(uid): try: uid = int(uid) except ValueError: uid = getCurrentUid() user = UserModel.getUser(uid) if request.method == "POST": size = len(request.data) / 1000000 if size > 2: return json.dumps({ "result": "fail", "msg": "File can not be more than 2 MB" }) newFileName = str(uid) + "_" + generateCode(10) + ".jpg" with open(UPLOAD_FOLDER + "/users/up/" + newFileName, "wb") as fh: fh.write(request.data) UserModel.updateProfilePhoto(getCurrentUid(), newFileName) #Delete old uploaded file if user["photo"] != None: try: os.remove(UPLOAD_FOLDER + "/users/up/" + user["photo"]) except: print("File couldn't be removed!") return json.dumps({"result": "success"}) return json.dumps({"result": "fail"})
def seaterPage(projectName, sid): project = ProjectModel.getProjectByProjectName(projectName) seater = SeaterModel.getSeater(sid, getCurrentUid()) seater["skills"] = SkillModel.getSeaterSkills(sid) assignedUser = UserModel.getUser(seater["uid"]) seater["isProjectAdmin"] = ProjectModel.isProjectAdmin(getCurrentUid(), project["pid"]) return render_template( "seater-page.html", currentUser= getCurrentUser(), seater = seater, assignedUser = assignedUser )
def getUser(): if request.method == "GET": uid = request.args.get("uid") username = request.args.get("username") email = request.args.get("email") if uid != None: user = UserModel.getUser(uid) elif username != None: user = UserModel.getUserByUsername(username) elif email != None: user = UserModel.getUserByEmail(email) else: return render_template("private-api/unknown-request.html") try: user.pop("password") except: print("password field cannot be popped!") return return json.dumps(user, cls=DateTimeEncoder) return redirect(url_for("index"))
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)