Inheritance: DomainEntity, IUser
 public string ThisUserHasBeenAuthenticated(User user, bool rememberMe)
 {
     string userData = String.Empty;
     userData = userData + "UserId=" + user.EntityId + "|CompanyId=" + user.Company.EntityId;
     var ticket = new FormsAuthenticationTicket(1, user.FullName, DateTime.Now, DateTime.Now.AddMinutes(30), rememberMe, userData);
     string encTicket = FormsAuthentication.Encrypt(ticket);
     var faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
     HttpContext.Current.Response.Cookies.Add(faCookie);
     return FormsAuthentication.GetRedirectUrl(user.FullName, false);
 }
 public PartialViewResult KnowYourTurfHeader()
 {
     User user = new User();
     if (User.Identity.IsAuthenticated)
     {
         user = _sessionContext.GetCurrentUser();
     }
     var inAdminMode = _sessionContext.RetrieveSessionObject(WebLocalizationKeys.INADMINMODE.ToString());
     if (inAdminMode == null)
     {
         _sessionContext.AddUpdateSessionItem(new SessionItem { SessionKey = WebLocalizationKeys.INADMINMODE.ToString(), SessionObject = false });
         inAdminMode = false;
     }
     HeaderViewModel model = new HeaderViewModel
     {
         User = user,
         LoggedIn = User.Identity.IsAuthenticated,
         IsAdmin = (user.UserRoles.IsNotEmpty() && user.UserRoles.Contains(UserRole.Admin.ToString())),
         InAdminMode = (bool)inAdminMode
     };
     return PartialView(model);
 }
        public ActionResult AddUpdate(ViewModel input)
        {
            var companys = _selectListItemService.CreateList<Company>(x => x.Name, x => x.EntityId, true);

            User user;
            UserLoginInfo loginInfo = new UserLoginInfo();
            int subscriptionLevel = 0;
            if (input.EntityId > 0)
            {
                loginInfo = _repository.Find<UserLoginInfo>(input.EntityId);
                user = loginInfo.User;
            }
            else
            {
                user = new User();
            }

            var model = new UserViewModel
                            {
                                User = user,
                                UserLoginInfo = loginInfo,
                                CompanyList = companys,
                                _Title =
                                    input.EntityId > 0
                                        ? WebLocalizationKeys.USER.ToString()
                                        : WebLocalizationKeys.ADD_NEW + " " + WebLocalizationKeys.USER,
                            };
            if (loginInfo.CompanyId > 0)
            {
                // stupid problem with dropdownlists
                var company = _repository.Find<Company>(loginInfo.CompanyId);
                model.Client = loginInfo.CompanyId;
                model.UsersCompany = company;
            }
            return View(model);
        }
示例#4
0
        private void CreateUser()
        {
            var defaultUser = new User
            {
                LoginName = "Admin",
                Password = "******",
                FirstName = "Raif",
                LastName = "Harik",
                UserRoles = UserRole.Admin.ToString(),
                UserType = UserType.Admin.ToString(),
                Company = _company

            };
            var altUser = new User
            {
                LoginName = "alt",
                Password = "******",
                FirstName = "Amahl",
                LastName = "Harik",
                UserRoles = UserRole.Admin.ToString(),
                UserType = UserType.Admin.ToString(),
                Company = _company

            };

            _repository.Save(defaultUser);
            _repository.Save(altUser);
        }
示例#5
0
 public virtual void RemoveSubscriber(User subscriber)
 {
     _subscribers.Remove(subscriber);
 }
示例#6
0
 public virtual void AddSubscriber(User subscriber)
 {
     if (!subscriber.IsNew() && _subscribers.Contains(subscriber)) return;
     _subscribers.Add(subscriber);
 }
 private void handlePassword(User origional, UserViewModel input)
 {
     if (input.Password.IsNotEmpty())
     {
         var loginInfo = origional.UserLoginInfos.FirstOrDefault(x => x.EntityId == input.UserLoginInfo.EntityId);
         loginInfo.Salt = _securityDataService.CreateSalt();
         loginInfo.Password = _securityDataService.CreatePasswordHash(input.Password, loginInfo.Salt);
     }
 }
        private void mapProperties(User origional, UserViewModel input)
        {
            origional.BirthDate = input.User.BirthDate;
            origional.FirstName = input.User.FirstName;
            origional.LastName = input.User.LastName;
            origional.BirthDate = input.User.BirthDate;
            if (input.DefaultEmail.IsNotEmpty())
            {
                origional.AddEmail(new Email { EmailAddress = input.DefaultEmail, IsDefault = true });
            }

            var loginInfo = origional.UserLoginInfos.FirstOrDefault(x => x.EntityId == input.UserLoginInfo.EntityId);
            loginInfo.LoginName = input.UserLoginInfo.LoginName;
            loginInfo.ClientId = input.Client > 0 ? input.Client : loginInfo.ClientId;
            loginInfo.IsActive = true;
            
        }
        public JsonResult Save(UserViewModel input)
        {
            User origional;
            if (input.EntityId > 0)
            {
                origional = _repository.Find<User>(input.EntityId);
            }
            else
            {
                origional = new User();
                var userLoginInfo = new UserLoginInfo();
                origional.AddUserLoginInfo(userLoginInfo);
            }
            mapProperties(origional, input);
            handlePassword(origional, input);

            var loginInfo = input.UserLoginInfo.EntityId == 0
                                ? origional.UserLoginInfos.FirstOrDefault()
                                : origional.UserLoginInfos.FirstOrDefault(
                                    x => x.EntityId == input.UserLoginInfo.EntityId);
            assignUserGroupAndPermissions(loginInfo);

            var crudManager = _saveEntityService.ProcessSave(origional);
            var notification = crudManager.Finish();
            return Json(notification, JsonRequestBehavior.AllowGet);
        }