protected API_Response <T> InvokeAPI <T>(Func <T> action, string api_key, bool checkKey = true) { Logger.Write_Message($"Start InvokeAPI: {new StackTrace().GetFrame(1).GetMethod().Name}"); API_Response <T> responce = null; Stopwatch clock = Stopwatch.StartNew(); try { responce = (!String.IsNullOrEmpty(SessionID) || !checkKey || API_KeyHelper.CheckKey(api_key)) ? new API_Response <T>(action(), $"{clock.ElapsedMilliseconds} ms") : new API_Response <T>(default(T), $"{clock.ElapsedMilliseconds} ms", EN_ErrorCodes.Forbidden, HttpStatusCode.Forbidden); } catch (ExodusException ex) { string message = Logger.Write_Error(ex); return(new API_Response <T>(default(T), $"{clock.ElapsedMilliseconds} ms", ex.ErrorCode, HttpStatusCode.InternalServerError, message)); } catch (Exception ex) { string message = Logger.Write_Error(ex); return(new API_Response <T>(default(T), $"{clock.ElapsedMilliseconds} ms", EN_ErrorCodes.SystemExeption, HttpStatusCode.InternalServerError, message)); } finally { Logger.Write_Message($"End InvokeAPI: {new StackTrace().GetFrame(1).GetMethod().Name}"); } return(responce); }
public API_Response <VM_User> Login(DTO_UserLogin model) { return(InvokeAPI(() => { VM_User user = null; if (!Global.Cache.CheckEmailExists(model.UserName)) { throw new Exception("User Not Found"); } // var UserLoginDetails = _DL.User.Account.LoginDetails_ByEmail(model.UserName); // Check User Login Details if (ModelState.IsValid) { // Check Password if (HashHMACSHA1.CheckSaltedHash(model.UserPassword, UserLoginDetails.PasswordHash)) { user = _DL.User.Get.ByID(UserLoginDetails.UserID); // Get User user.ApiKey = API_KeyHelper.GenarateKey(user.UserID); // Generate Token } else { throw new Exception("Incorrect password"); } } else { throw new Exception("Login Error"); } return user; }, "", false)); }