Exemple #1
0
def isThereThisUsername(username):
    data = dict()
    if UserModel.isThereThisUsername(username):
        data["result"] = True
    else:
        data["result"] = False

    return json.dumps(data)
Exemple #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)
Exemple #3
0
def checkUsernameAvailability(username):
    return json.dumps({"result": not UserModel.isThereThisUsername(username)})