Esempio n. 1
0
def userProfile(username):
    currentUser = getCurrentUser()
    user = UserModel.getUserByUsername(username, getCurrentUid())

    if user == None:
        return render_template("not-found.html",
                               title="User Not Found!",
                               msg="The user you trying to access not found!",
                               currentUser=getCurrentUser())

    userLinks = UserModel.getUserLinks(user["uid"])
    userProjects = ProjectModel.getUserProjects(user["uid"])
    lastUserPosts = UserPostModel.getLastUserPosts(user["uid"], 10,
                                                   getCurrentUid())
    popularProjects = ProjectModel.getPopularProjects(10)
    whoToFollowList = UserModel.getWhoToFollowList(5, getCurrentUid())

    #Remove password and email fields
    user.pop("password")
    user.pop("email")

    return render_template("user-profile.html",
                           currentUser=currentUser,
                           user=user,
                           userLinks=userLinks,
                           userProjects=userProjects,
                           lastUserPosts=lastUserPosts,
                           popularProjects=popularProjects,
                           whoToFollowList=whoToFollowList)
Esempio n. 2
0
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)
Esempio n. 3
0
def getUserProjects(uid):
    projects = ProjectModel.getUserProjects(uid)

    return json.dumps(projects, cls=DateTimeEncoder)