Ejemplo n.º 1
0
 public void StartValidUserSession(LoginAppUserVM loginAppUserVM)
 {
     if (loginAppUserVM != null)
     {
         //Put Valid Login User Data in Session
         GameUserIdentity.LoggedInUser = loginAppUserVM;
     }
 }
Ejemplo n.º 2
0
        public ReturnMessage GetAuthenticateUser(string szUsername, string szPassword)
        {
            try
            {
                if (string.IsNullOrEmpty(szUsername.Trim()) || string.IsNullOrEmpty(szPassword.Trim()))
                {
                    return(new ReturnMessage
                    {
                        Success = false,
                        Message = "Please enter valid credentials."
                    });
                }
                var retVal = _IAppUserRepository.GetAppUser(null, szUsername);
                //If User Found
                if (retVal != null && retVal.AppUserId > 0)
                {
                    //Check if User has been Deleted
                    if (retVal.isDeleted)
                    {
                        return(new ReturnMessage
                        {
                            Success = false,
                            Message = $"Sorry, {szUsername} has been Deleted. Please contact Admin."
                        });
                    }
                    //Check if User has been Disabled
                    if (retVal.iStatus > 0)
                    {
                        return(new ReturnMessage
                        {
                            Success = false,
                            Message = $"Sorry, {szUsername} has been Disabled. Please contact Admin."
                        });
                    }

                    var passwordSalt      = retVal.szPasswordSalt.ToString();
                    var originalPassword  = retVal.szPassword.Trim();
                    var decryptedPassword = Encryption.SaltDecrypt(originalPassword, passwordSalt);

                    //password correct
                    if (decryptedPassword.Trim() == szPassword.Trim())
                    {
                        //Login User
                        string loginToken = Guid.NewGuid().ToString();
                        _IAppUserRepository.LoginAppUser(retVal.szUsername, true, loginToken);

                        LoginAppUserVM loginAppUserVM = new LoginAppUserVM
                        {
                            AppUserId      = retVal.AppUserId,
                            szImgURL       = retVal.szImgURL,
                            szUsername     = retVal.szUsername,
                            iStatus        = retVal.iStatus,
                            iChangePW      = retVal.iChangePW,
                            userLoginToken = loginToken
                        };
                        return(new ReturnMessage
                        {
                            ID = retVal.AppUserId,
                            Success = true,
                            Message = "Login Successful",
                            Data = loginAppUserVM
                        });
                    }
                    else
                    {
                        return(new ReturnMessage
                        {
                            Success = false,
                            Message = "Password Incorrect. Forgotten your password?. You can reset it."
                        });
                    }
                }
                else
                {
                    return(new ReturnMessage
                    {
                        Success = false,
                        Message = "Invalid Credentials. Check your entry and try again."
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ReturnMessage
                {
                    Success = false,
                    Message = "Error Encountered: " + ex.Message
                });
            }
        }