Esempio n. 1
0
        /// <summary>
        /// AttemptToLogUserIn method
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public LoginModel AttemptToLogUserIn(string userName, string password)
        {
            LoginModel myLoginModel = new LoginModel();

            var myUserManagement = new UserManagement();
            var authenticationResult = myUserManagement.Authenticate(userName, password);

            if ((authenticationResult == UserManagement.AuthenticationResults.InvalidPassword)
                || (authenticationResult == UserManagement.AuthenticationResults.NoMatchingUser))
            {
                myLoginModel.Message = Constants.Areas.Common.LoginModel.AuthenticationResultMessages.BadOrIncorrectUsernameOrPassword;
                myLoginModel.Errors = true;
                return myLoginModel;
            }

            if (authenticationResult == UserManagement.AuthenticationResults.ChangePassword)
            {
                myLoginModel.Message = Constants.Areas.Common.LoginModel.AuthenticationResultMessages.ChangePassword;
                myLoginModel.Errors = true;
                return myLoginModel;
            }

            if (authenticationResult != UserManagement.AuthenticationResults.Success)
            {
                myLoginModel.Message = Constants.Areas.Common.LoginModel.AuthenticationResultMessages.UnknownResult;
                myLoginModel.Errors = true;
                return myLoginModel;
            }

            myLoginModel.User = myUserManagement.GetUserDetails(userName);
            myLoginModel.Groups = myUserManagement.GetUserGroups(userName);

            if(myLoginModel.User == null || myLoginModel.Groups.Count == 0)
            {
                myLoginModel.Message = Constants.Areas.Common.LoginModel.AuthenticationResultMessages.NoUserRoles;
                myLoginModel.Errors = true;
                return myLoginModel;
            }

            return myLoginModel;
        }