Exemplo n.º 1
0
 public bool Add(UserProfile entity, string store, string application)
 {
     try
     {
         AddUserToRoles(entity.UserName, entity.Roles, store, application);
         _unitOfWork.Save();
         return true;
     }
     catch (ApplicationException ex)
     {
         throw new ApplicationException(string.Format("An error occurred while saving. Detail: {0} ", ex.Message));
     }
 }
Exemplo n.º 2
0
 public bool Add(UserProfile entity, Dictionary<string, List<string>> roles)
 {
     try
     {
         // Add the user account first and latter set default preference and profiles for user
         _unitOfWork.UserProfileRepository.Add(entity);
         _unitOfWork.Save();
         foreach (var Role in roles)
             AddUserToRoles(entity.UserName, Role.Value.ToArray(), "CATS", Role.Key);
         _unitOfWork.Save();
         return true;
     }
     catch (ApplicationException ex)
     {
         throw new ApplicationException(string.Format("An error occurred while saving. Detail: {0} ", ex.Message));
     }
 }
Exemplo n.º 3
0
 public UserIdentity(UserProfile user)
 {
     this.userName = user.UserName;
     this.authenticated = true;
 }
Exemplo n.º 4
0
        public ActionResult New(UserViewModel userInfo)
        {
            //var messages = new List<string>();

            //// Check business rule and validations
            //if (userInfo.UserName == string.Empty)
            //    messages.Add("User name cannot be empty");
            //if (userInfo.FirstName == string.Empty)
            //    messages.Add("First name cannot be empty");
            //if (userInfo.LastName == string.Empty)
            //    messages.Add("Last Name cannot be empty");
            //if (userInfo.Password == string.Empty)
            //    messages.Add("Password cannot be empty");
            //if (userInfo.Password != userInfo.PasswordConfirm)
            //    messages.Add("Passwords do not match");

            //if (messages.Count > 0)
            //    return View();

            // If the supplied information is correct then persist it to the database
            var user = new UserProfile();

            user.UserName = userInfo.UserName;
            user.Password = _userService.HashPassword(userInfo.Password);

            // Set default values for required fields
            user.Disabled = false;
            user.LockedInInd = false;
            user.ActiveInd = true;
            user.NumberOfLogins = 0;

            //List<Cats.Models.Security.ViewModels.Application> app = userInfo.Applications;
            Dictionary<string, List<string>> roles = new Dictionary<string, List<string>>();
            //List<string> Roles;
            //foreach (var application in app)
            //{
            //    Roles = new List<string>();
            //    foreach (var role in application.Roles)
            //    {
            //        if (role.IsChecked)
            //            Roles.Add(role.RoleName);
            //    }
            //    if (Roles.Count > 0)
            //        roles.Add(application.ApplicationName, Roles);
            //}

            user.FirstName = userInfo.FirstName;
            user.LastName = userInfo.LastName;

            user.LanguageCode = "EN";
            user.Keyboard = "AM";
            user.PreferedWeightMeasurment = "MT";
            user.DatePreference = "GC";
            user.DefaultTheme = "Default";
            user.FailedAttempts = 0;
            user.LoggedInInd = false;

            if(_userService.Add(user, roles))
            {
                return View("Index");
            }

            return View();
        }
Exemplo n.º 5
0
        public ActionResult EditUser(UserProfile userInfo)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.FindById(userInfo.UserProfileID);
                user.UserName = userInfo.UserName;
                user.FirstName = userInfo.FirstName;
                user.LastName = userInfo.LastName;
                user.GrandFatherName = userInfo.GrandFatherName;
                user.RegionalUser = userInfo.RegionalUser;
                user.RegionID = userInfo.RegionalUser ? userInfo.RegionID : null;
                user.RegionID = userInfo.RegionID;
                user.DefaultHub = userInfo.DefaultHub;
                user.CaseTeam = userInfo.CaseTeam;
                user.MobileNumber = userInfo.MobileNumber;
                user.Email = userInfo.Email;

                if (_userService.UpdateUser(user))
                {
                    return View("Index");
                }
            }
            init();
            ViewBag.hubs = _hubService.GetAllHub().ToList();
            ViewBag.regions = _adminUnitService.GetRegions();
            return View("EditUser");
        }
Exemplo n.º 6
0
 public bool UpdateUser(UserProfile entity)
 {
     _unitOfWork.UserProfileRepository.Edit(entity);
     _unitOfWork.Save();
     return true;
 }
Exemplo n.º 7
0
 public bool Delete(UserProfile entity)
 {
     if (entity == null) return false;
     _unitOfWork.UserProfileRepository.Delete(entity);
     _unitOfWork.Save();
     return true;
 }
Exemplo n.º 8
0
        public bool ChangePassword(UserProfile userInfo, string password)
        {
            try
            {
                var user = _unitOfWork.UserProfileRepository.FindBy(u => u.UserProfileID == userInfo.UserProfileID).SingleOrDefault();
                if (user != null)
                {
                    user.Password = HashPassword(password);
                    _unitOfWork.Save();
                    return true;
                }
            }

            catch (Exception e)
            {
                //throw new ApplicationException("Error changing password", e);
                throw new passwordChangeException(e);
            }
            return false;
        }
Exemplo n.º 9
0
 public bool Authenticate(UserProfile userInfo)
 {
     return Authenticate(userInfo.UserName, userInfo.Password);
 }
Exemplo n.º 10
0
        public ActionResult New(UserProfile userInfo)
        {
            if (!ModelState.IsValid)
            {

                init();
                return View();
            }

            if (userInfo.Password != userInfo.PasswordConfirm)
            {
                ViewBag.passworDoNotMatch = "Password must match!";
                init();
                return View();
            }

            var user_ = _userService.FindBy(u=>u.UserName == userInfo.UserName).FirstOrDefault();

            var user = new UserProfile();

            user.UserName = userInfo.UserName;
            user.Password = _userService.HashPassword(userInfo.Password);
            user.ProgramId = userInfo.ProgramId;
            // Set default values for required fields
            user.Disabled = false;
            user.LockedInInd = false;
            user.ActiveInd = true;
            user.NumberOfLogins = 0;

            Dictionary<string, List<string>> roles = new Dictionary<string, List<string>>();

            user.FirstName = userInfo.FirstName;
            user.LastName = userInfo.LastName;
            user.RegionalUser = userInfo.RegionalUser;
            user.RegionID = userInfo.RegionID;
            user.CaseTeam = userInfo.CaseTeam;
            user.IsAdmin = userInfo.IsAdmin;
            user.TariffEntry = userInfo.TariffEntry;
            user.LanguageCode = "EN";
            user.Keyboard = "AM";
            user.PreferedWeightMeasurment = "MT";
            user.DatePreference = "GC";
            user.DefaultTheme = "Default";
            user.FailedAttempts = 0;
            user.LoggedInInd = false;
            user.Email = userInfo.Email;

            user.DefaultHub = userInfo.DefaultHub ?? userInfo.DefaultHub;

            if (user_ != null)
            {
                ViewBag.Error = "User Name exits!.Please choose a different User Name!";
                init();
                return View();
            }

            if(_userService.Add(user, roles))
            {
                if (user.DefaultHub.HasValue)
                {
                    var _savedUser = _userService.FindBy(u => u.UserName == userInfo.UserName).FirstOrDefault();
                    _userHubServcie.AddUserHub(user.DefaultHub.Value, _savedUser.UserProfileID);
                }
                return View("Index");
            }
            return View();
        }