Ejemplo n.º 1
0
def login():
    # Find out what URL to hit for Google login
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        # hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
        # print(hashed_password)
        usr_checked = mongoUsr.login(bcrypt, username, password)
        if usr_checked:
            # @login_manager.user_loader
            global user
            global first_Name
            global profile_pic
            global id_
            id_ = mongoUsr.get_id(usr_checked.username)
            user = logUsr.user_info.get(id_)
            name = mongoUsr.get_name(id_)
            first_Name = name.split(' ', 1)[0]
            profile_pic = mongoUsr.get_profile_pic(id_)
            login_user(user)
            try:
                return redirect(last_url[-1])
            except: 
                return redirect(url_for("index"))
        else:
            print("login failed")

        return redirect(url_for("index"))

    elif request.method == 'GET':
        google_provider_cfg = get_google_provider_cfg()
        authorization_endpoint = google_provider_cfg["authorization_endpoint"]

        # Use library to construct the request for login and provide
        # scopes that let you retrieve user's profile from Google
        request_uri = client.prepare_request_uri(
            authorization_endpoint,
            redirect_uri=request.base_url + "/callback",
            scope=["openid", "email", "profile"],
        )
        print(request_uri)
        return redirect(request_uri)
Ejemplo n.º 2
0
 def verify(self):
     mdict = mongo.login(self.username, self.hashed_password)
     if mdict:
         return True
     return False