sharee.bike-App/SharedBusinessLogic/Repository/Exception/AuthcookieNotDefinedException.cs

63 lines
2.8 KiB
C#
Raw Normal View History

2024-04-09 12:53:23 +02:00
namespace ShareeBike.Repository.Exception
2021-05-13 20:03:07 +02:00
{
2022-09-06 16:08:19 +02:00
/// <summary>
2023-06-06 12:00:24 +02:00
/// Is fired with request used a cookie which is not defined.
2022-09-06 16:08:19 +02:00
/// Reasons for cookie to be not defined might be
2023-06-06 12:00:24 +02:00
/// - user used more that 8 different devices (copri invalidates cookies in this case)
2022-09-06 16:08:19 +02:00
/// - user account has been deleted?
/// </summary>
public class AuthcookieNotDefinedException : InvalidResponseException<Response.ResponseBase>
{
/// <summary>Constructs a authorization exceptions. </summary>
/// <param name="p_strTextOfAction">Text describing request which is shown if validation fails.</param>
public AuthcookieNotDefinedException(string p_strTextOfAction, Response.ResponseBase response) :
base($"{p_strTextOfAction}\r\nDie Sitzung ist abgelaufen. Bitte neu anmelden.", response)
{
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets whether authcookie is defined or not.
/// </summary>
/// <param name="reponse">Response to check</param>
2023-06-06 12:00:24 +02:00
/// <param name="actionText">Text holding context in which authcookie is checked.</param>
2022-09-06 16:08:19 +02:00
/// <param name="exception">Exception thrown if cookie is not defined.</param>
/// <returns></returns>
public static bool IsAuthcookieNotDefined(
Response.ResponseBase reponse,
string actionText,
out AuthcookieNotDefinedException exception)
{
if (reponse == null || reponse.response_state == null)
{
2023-06-06 12:00:24 +02:00
// Empty response or response without response state is no authcookie not defined exception.
2022-09-06 16:08:19 +02:00
exception = null;
return false;
}
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
if (!reponse.response_state.ToUpper().Contains(AUTH_FAILURE_QUERY_AUTHCOOKIENOTDEFIED.ToUpper())
&& !reponse.response_state.ToUpper().Contains(AUTH_FAILURE_BOOK_AUTICOOKIENOTDEFIED.ToUpper())
&& !reponse.response_state.ToUpper().Contains(AUTH_FAILURE_BIKESOCCUPIED_AUTICOOKIENOTDEFIED.ToUpper())
&& !reponse.response_state.ToUpper().Contains(AUTH_FAILURE_LOGOUT_AUTHCOOKIENOTDEFIED.ToUpper()))
{
exception = null;
return false;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
exception = new AuthcookieNotDefinedException(actionText, reponse);
return true;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds error description if session expired. From COPRI 4.0.0.0 1001 is the only authcookie not defined error. </summary>
private const string AUTH_FAILURE_QUERY_AUTHCOOKIENOTDEFIED = "Failure 1001: authcookie not defined";
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds error description if session expired (Applies to COPRI < 4.0.0.0) </summary>
private const string AUTH_FAILURE_BOOK_AUTICOOKIENOTDEFIED = "Failure 1002: authcookie not defined";
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds error description if session expired (Applies to COPRI < 4.0.0.0) </summary>
private const string AUTH_FAILURE_BIKESOCCUPIED_AUTICOOKIENOTDEFIED = "Failure 1003: authcookie not defined";
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds error description if session expired. (Applies to COPRI < 4.0.0.0)</summary>
private const string AUTH_FAILURE_LOGOUT_AUTHCOOKIENOTDEFIED = "Failure 1004: authcookie not defined";
}
2021-05-13 20:03:07 +02:00
}