Exemple #1
0
        public GenericActionResult <UserDataModel> AuthenticateUser(string userName, string password)
        {
            var identityResult = this.Find(userName, password);

            UserDataModel userDataModel = null;

            if (identityResult != null)
            {
                if (identityResult.EmailConfirmed)
                {
                    userDataModel = _modelFactory.CreateUserDataModel(identityResult);

                    userDataModel.Roles =
                        _roleManager.GetRoleNames(identityResult.Roles.Select(c => c.RoleId).ToList()).ToList();

                    userDataModel.IsAuthenticated = true;

                    var authenticationResult = new GenericActionResult <UserDataModel>
                    {
                        Result    = userDataModel,
                        IsSuccess = true
                    };
                    return(authenticationResult);
                }
                else
                {
                    userDataModel = new UserDataModel {
                        IsAuthenticated = false
                    };
                    return(new GenericActionResult <UserDataModel>
                    {
                        Result = userDataModel,
                        IsSuccess = false,
                        Errors = new List <string> {
                            "Email has not been confirmed!"
                        }
                    });
                }
            }
            else
            {
                userDataModel = new UserDataModel {
                    IsAuthenticated = false
                };
                return(new GenericActionResult <UserDataModel>
                {
                    Result = userDataModel,
                    IsSuccess = false,
                    Errors = new List <string> {
                        "Incorrect username or password!"
                    }
                });
            }
        }