public Response <UserSession> Create(UserSession UserSessions) { var response = new Response <UserSession>(); try { UserSession newObj = new UserSession { AccessToken = UserSessions.AccessToken, UserId = UserSessions.UserId, CreationTime = DateTime.UtcNow.ToString(), }; _userSessionRepository.Insert(newObj); response.Success = true; response.Data = newObj; } catch (Exception ex) { HandleException(response, ex); } return(response); }
public void ConfirmUserRegistration(string confirmationKey) { if (string.IsNullOrWhiteSpace(confirmationKey)) { throw new ArgumentException("Not set", nameof(confirmationKey)); } var confirmation = _confirmationRepository.FindByConfirmationKey(confirmationKey); if (confirmation == null) { throw new ConfirmationNotFoundException(confirmationKey); } confirmation.Confirm(); _confirmationRepository.Update(confirmation); var user = _userRepository.GetById(confirmation.UserId); if (user == null) { throw new ApplicationException("Пользователь не зарегистрирован."); } user.Confirm(); _userRepository.Update(user); var userSession = _userSessionRepository.GetLastSession(confirmation.UserId); if (userSession == null) { userSession = new UserSession(confirmation.UserId); _userSessionRepository.Insert(userSession); } }
public AdminLoginResponse Login(string username, string password) { try { IAdminRepository adminRepository = RepositoryClassFactory.GetInstance().GetAdminRepository(); Admin _admin = adminRepository.FindByUserName(username); if (_admin != null) { if (_admin.Locked) { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_account_locked }); } } Admin admin = adminRepository.Login(username, password); if (admin != null) { IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository(); //Delete session id existed try { userSessionRepository.DeleteByUserID(admin.AdminID); } catch (Exception) { } int timeOut = TIME_OUT_MINUTES * 60 * 1000; UserSession userSession = new UserSession { CreatedDate = DateTime.Now, UserID = admin.AdminID, SessionID = Guid.NewGuid().ToString(), UpdatedDate = DateTime.Now }; object sessionID = userSessionRepository.Insert(userSession); return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.None, Message = "", SessionId = userSession.SessionID, AdminId = admin.AdminID, AdminName = admin.LastName }); } else { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_login_fail }); } } catch (Exception ex) { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }
public UserLoginResponse Login(string username, string password) { try { IUserRepository userRepository = RepositoryClassFactory.GetInstance().GetUserRepository(); User _user = userRepository.FindByUserName(username); if (_user != null) { if (_user.Locked) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_account_locked }); } } IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository(); User user = userRepository.Login(username, password); if (user != null) { try { userSessionRepository.DeleteByUserID(user.UserID); } catch (Exception) { } int timeOut = TIME_OUT_MINUTES * 60 * 1000; UserSession userSession = new UserSession { CreatedDate = DateTime.Now, UserID = user.UserID, SessionID = Guid.NewGuid().ToString(), UpdatedDate = DateTime.Now }; object sessionID = userSessionRepository.Insert(userSession); return(new UserLoginResponse { ErrorCode = (int)ErrorCode.None, Message = string.Empty, SessionId = userSession.SessionID, UserId = user.UserID, UserName = user.UserName }); } else { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_login_fail }); } } catch (Exception ex) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }