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!")
def google_register(google_user_id, user_email, avatar_link) -> m_LogicReturn: if v.value_empty(google_user_id) \ or v.value_empty(user_email): 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 not valid!") _User = m_User( first_name=None, surname=None, email=user_email, password_hash=None, phone_number=None, nfc_id=None, finger_id=None, friend_code=Tools.generate_friend_code(), google_user_id=google_user_id, avatar_link=avatar_link, verified=True ) db_resp = db_User().create_user(_User) if db_resp.success: return m_LogicReturn.f_error_msg(db_resp.content) return m_LogicReturn.f_success_msg(db_resp.content)
def register(user_email, user_password, user_password2) -> m_LogicReturn: if v.value_empty(user_email) \ or v.value_empty(user_password) \ or v.value_empty(user_password2): return m_LogicReturn.f_error_msg("post data is missing") v_pass = v.verify_password(user_password) if not v_pass.success: return m_LogicReturn.f_error_msg(v_pass.content) if not v.verify_email(user_email): return m_LogicReturn.f_error_msg("E-mail is invalid") if user_password != user_password2: return m_LogicReturn.f_error_msg("Passwords are not the same!") password_hash = Encryption.encrypt_password( user_password) _User = m_User( first_name=None, surname=None, email=user_email, password_hash=password_hash, phone_number=None, nfc_id=None, finger_id=None, friend_code=Tools.generate_friend_code(), avatar_link="https://www.clevelanddentalhc.com/wp-content/uploads/2018/03/sample-avatar-300x300.jpg" ) db_resp = db_User().create_user(_User) if not db_resp.success: return m_LogicReturn.f_error_msg(db_resp.content) token_code = Token.generate_confirm_token(user_email) print(f"Token code: {token_code}") email_message = Email.get_register_email(user_email, token_code) email_resp = Email.send_email(user_email, email_message) if not email_resp.success: return m_LogicReturn.f_error_msg("Failed to send email!") return m_LogicReturn.f_success_msg(db_resp.content)
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!")