예제 #1
0
 private async Task SignInAsync(User user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
예제 #2
0
        public JsonResult Delete(User user)
        {
            if (user.UserName != User.Identity.Name)
            {
                accountService.DeleteUser(user);
                return Json(true);
            }
            else

            { return Json(false); }
        }
예제 #3
0
        public JsonResult Edit(CreateUserViewModel user)
        {
            if (ModelState.IsValid)
            {
                var updateUser = new User()
                {
                    Id = user.Id.ToString(),
                    UserName = user.UserName,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    SecretQuestion = user.SecretQuestion,
                    SecretAnswer = user.SecretAnswer,
                    Email = user.Email,
                    Phone1 = user.Phone1,
                    Phone2 = user.Phone2,
                    Address1 = user.Address1,
                    Address2 = user.Address2,
                    City = user.City,
                    State = user.State,
                    Zip = user.Zip,
                    Fax = user.Fax,
                    CreateDate = DateTime.Now,
                    Active = user.Active

                };

                if (!string.IsNullOrEmpty(user.Password))// Password has changed
                {
                    var newPwd = Oas.Service.Security.Encryptor.MD5Hash(user.Password);
                    var result = UserManager.AddPassword(updateUser.Id, newPwd);
                }
                accountService.UpdateUserInfo(updateUser);
                return Json(true);//Json(updateUser, JsonRequestBehavior.AllowGet);
            }
            return Json(false);
        }
예제 #4
0
        public bool DeleteUser(User user)
        {
            using (var dbContext = new DatabaseContext())
            {

                var rDel = dbContext.Users.Include(t => t.Roles).FirstOrDefault(r => r.Id.Equals(user.Id));

                if (rDel != null)
                {
                    dbContext.Users.Remove(rDel);
                    dbContext.SaveChanges();
                    return true;
                }
            }

            return false;
        }
예제 #5
0
        public JsonResult Create(CreateUserViewModel user)
        {
            if (ModelState.IsValid)
            {
                var newUser = new User()
                {
                    Id = Guid.NewGuid().ToString(),

                    UserName = user.UserName,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    SecretQuestion = user.SecretQuestion,
                    SecretAnswer = user.SecretAnswer,
                    Email = user.Email,
                    Phone1 = user.Phone1,
                    Phone2 = user.Phone2,
                    Address1 = user.Address1,
                    Address2 = user.Address2,
                    City = user.City,
                    State = user.State,
                    Zip = user.Zip,
                    Fax = user.Fax,
                    CreateDate = DateTime.Now,
                    Active = user.Active

                };
                try
                {

                    //var password = Encryptor.MD5Hash(user.Password);

                    IdentityResult result = UserManager.Create(newUser, user.Password);

                    if (result.Succeeded)
                    {
                        UserManager.AddToRoleAsync(newUser.Id, UserRoles.Employee); ;
                        return Json(true);
                    }
                    return Json(false);
                }
                catch (Exception ex)
                {
                    //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }
            return Json(true);
        }
예제 #6
0
 public bool CreateUser(User user, string password)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public bool CreateUser(User user)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public void UpdateUserInfo(User user)
 {
     accountRepository.Update(user);
 }
예제 #9
0
        public async Task<ActionResult> Register(CreateUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, "abcde12345-");
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #10
0
        public ActionResult LogOut()
        {
            Session["IsLock"] = true;

            var userInfo = accountService.Get(User.Identity.GetUserId());

            User user = new TDevs.Domain.User()
            {
                UserName = userInfo.UserName,
                FirstName = userInfo.FirstName,
                LastName = userInfo.LastName,
                Email = userInfo.Email
            };
            Session["User"] = user;
            AuthenticationManager.SignOut();
            //FormsAuthentication.RedirectToLoginPage("/Home/LockScreen");
            return Json(user, JsonRequestBehavior.AllowGet);
        }
예제 #11
0
        public ActionResult LockScreen()
        {
            Session["IsLock"] = true;

            var userInfo = accountService.Get(User.Identity.GetUserId());

            User user = new TDevs.Domain.User()
            {
                UserName = userInfo.UserName,
                FirstName = userInfo.FirstName,
                LastName = userInfo.LastName,
                Email = userInfo.Email
            };
            Session["User"] = user;
            AuthenticationManager.SignOut();
            return RedirectToAction("Index", "Home");
        }
예제 #12
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }