Exemplo n.º 1
0
    def login(user_email, user_password) -> m_LogicReturn:
        if v.value_empty(user_email) \
           or v.value_empty(user_password):
            return m_LogicReturn.f_error_msg("Post data is missing!")

        if not v.verify_email(user_email):
            return m_LogicReturn.f_error_msg("E-mail is invalid!")
        v_pass = v.verify_password(user_password)
        if not v_pass.success:
            return m_LogicReturn.f_error_msg(v_pass.content)

        db_resp = db_User().get_user(
            m_UserEntries.email,
            user_email
        )

        if not db_resp.success:
            return m_LogicReturn.f_error_msg("Wrong email/password combination")

        _User = db_resp.addon_data
        _User: m_User

        if not Encryption.verify_password(
                user_password, _User.password_hash):
            return m_LogicReturn.f_error_msg("Wrong email/password combination")

        if not _User.verified:
            return m_LogicReturn.f_error_msg("User did not verify via email.")

        logic_resp = SessionLogic.login(_User)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Logged in!")
Exemplo n.º 2
0
    def facebook_login(access_token, name, userid) -> m_LogicReturn:
        if v.value_empty(access_token) \
            or v.value_empty(name) \
                or v.value_empty(userid):
            return m_LogicReturn.f_error_msg("missing data!")

        logic_resp = SocialsLogic.fb_verify_access_token(access_token)
        if not logic_resp:
            return m_LogicReturn.f_error_msg("invalid access token")

        db_resp = db_User().get_user(
            m_UserEntries.facebook_user_id,
            userid
        )
        if not db_resp.success:
            logic_resp = AuthLogic.facebook_register(name, userid)
            if not logic_resp.success:
                return m_LogicReturn.f_error_msg(logic_resp.content)
        db_resp = db_User().get_user(
            m_UserEntries.facebook_user_id,
            userid
        )
        _User = db_resp.addon_data
        _User: m_User

        logic_resp = SessionLogic.login(_User)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Logged in!")
Exemplo n.º 3
0
    def google_login(google_token_id, user_email, client_id, avatar_link) -> m_LogicReturn:
        if v.value_empty(google_token_id) \
            or v.value_empty(user_email) \
                or v.value_empty(client_id) \
                or v.value_empty(avatar_link):
            return m_LogicReturn.f_error_msg("Data is missing!")

        if not v.verify_email(user_email):
            return m_LogicReturn.f_error_msg("E-mail is invalid!")

        logic_resp = SocialsLogic.verify_token_id(google_token_id, client_id)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg("invalid id token")

        google_user_id = logic_resp.addon_data

        db_resp = db_User().get_user(
            m_UserEntries.google_user_id,
            google_user_id
        )
        if not db_resp.success:
            logic_resp = AuthLogic.google_register(
                google_user_id, user_email, avatar_link)
            if not logic_resp.success:
                return m_LogicReturn.f_error_msg(logic_resp.content)

        db_resp = db_User().get_user(
            m_UserEntries.google_user_id,
            google_user_id
        )
        _User = db_resp.addon_data
        _User: m_User

        logic_resp = SessionLogic.login(_User)
        if not logic_resp.success:
            return m_LogicReturn.f_error_msg(logic_resp.content)
        return m_LogicReturn.f_success_msg("Logged in!")