Beispiel #1
0
 public void Init()
 {
     Repo = new Mock<Repository<User>>();
     FormsAuth = new Mock<IFormsAuthService>();
     Controller = new UserController(Repo.Object,FormsAuth.Object);
     User = new NewUserNoChildrenFixture().GetInstance();
     LoginInput = new LoginInputNewUserNoChildrenFixture().GetInstance();
     RegisterInput = new RegisterInputCompleteFixture().GetInstance();
     AuthService = new UserAuthService(User,Repo.Object);
 }
        public ActionResult Create(User user)
        {
            if (!UserHelper.GetCurrent().IsAdmin) return View("AccesoDenegdo");
            if (ModelState.IsValid)
            {
                user.HashedPass = DataHashing.Compute(Algorithm.SHA1, user.HashedPass);
                _userRepository.Save(user);

                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }
        public virtual void Load( Guid id )
        {
            Roles = new List<EmployeeRole>();

             User = queryEmployees.Load(id);
            if(User == null ) return;

            var empRoles = User.Roles.ToList();
             var roles = queryRoles.Query().ToList();

            roles.ForEach(role => Roles.Add(
                new EmployeeRole{
                    Role=role,
                    IsLinked = empRoles.Exists(r => r== role)
                }));
        }
Beispiel #4
0
 public ActionResult CreateAccount(AccountModels.RegisterModel model)
 {
     var context = DependencyResolver.Current.GetService<DbContext>();
     if (ModelState.IsValid)
     {
         var user = new User()
         {
             Name = model.Username,
             Password = Hash.CreateHash(model.Password),
             Email = model.Email
         };
         context.Set<User>().Add(user);
         context.SaveChanges();
         FormsAuthentication.SetAuthCookie(model.Username, true);
         return RedirectToAction("Index", "Home");
     }
     return View(model);
 }
        // **************************************
        // URL: /Account/LogOff
        // **************************************
        public ActionResult LogOff()
        {
            FormsService.SignOut();
            Usuario = null;

            return RedirectToAction("Index", "PostManager");
        }
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = _userRepository.GetByLoginPass(model.UserName, DataHashing.Compute(Algorithm.SHA1, model.Password));

                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    Usuario = user;

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "PostManager");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Usuario y/o Clave Incorrecta.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public ActionResult Edit(User user)
 {
     if (!UserHelper.GetCurrent().IsAdmin) return View("AccesoDenegdo");
     if (ModelState.IsValid)
     {
         var entity = _userRepository.GetById(user.Id);
         entity.IsAdmin = user.IsAdmin;
         entity.Name = user.Name;
         return RedirectToAction("Index");
     }
     else
     {
         return View();
     }
 }
Beispiel #8
0
 public virtual void AddEmployee( User employee )
 {
     Employees.Add(employee);
 }