Exemplo n.º 1
0
        public async Task <ActionResult> ChangePassword(string confirmPassword, string newPassword,
                                                        string currentPassword)
        {
            try
            {
                var hashedPassword = UserManagerApp.PasswordHasher.HashPassword(currentPassword);
                var user           = await UserManagerApp.FindByIdAsync(this.User.Identity.GetUserId());

                if (newPassword == confirmPassword)
                {
                    IdentityResult result =
                        await
                        UserManagerApp.ChangePasswordAsync(User.Identity.GetUserId(), currentPassword, newPassword);

                    if (result.Succeeded)
                    {
                        //  Success("Password updated succesfully");
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                //  Danger("Something was wrong");
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Delete(string id)
        {
            try
            {
                UserApp user = await UserManagerApp.FindByIdAsync(id);

                IdentityResult result = await UserManagerApp.DeleteAsync(user);

                if (result.Succeeded)
                {
                    // Success("User Successfuly deleted!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //Danger("Failed! Something was wrong!");
                    ModelState.AddModelError("", "error");
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                //Danger("Failed! Something was wrong!");
                throw;
            }
        }
Exemplo n.º 3
0
        public UserManagerApp Create(IdentityFactoryOptions <UserManagerApp> identitiyFactorOptions, Microsoft.Owin.IOwinContext owinContext)
        {
            DataContext    db   = owinContext.Get <DataContext>();
            UserManagerApp user = new UserManagerApp(new UserStore <Kullanici>(db));

            return(user);
        }
Exemplo n.º 4
0
        public async Task <JsonResult> Create(UserApp user, string password)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UserApp u = new UserApp();
                    u.UserName          = user.Email;
                    u.LastLoginDateTime = DateTime.Now;
                    u.FullName          = user.FullName;
                    u.PhoneNumber       = user.PhoneNumber;
                    u.Email             = user.Email;

                    IdentityResult UserAddResult = await UserManagerApp.CreateAsync(u, password);

                    if (UserAddResult.Succeeded)
                    {
                        UserApp thisUser = UserManagerApp.Find(user.Email, password);
                        if (thisUser != null)
                        {
                            ClaimsIdentity Ident = UserManagerApp.CreateIdentity(thisUser, DefaultAuthenticationTypes.ApplicationCookie);
                            HttpContext.GetOwinContext().Authentication.SignOut();

                            HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties()
                            {
                                IsPersistent = false
                            }, Ident);
                            return(Json(new { status = "login" }));
                        }

                        return(Json(new { status = "ok" }));
                        //IdentityResult RoleAddResult = await UserManagerApp.AddToRoleAsync(u.Id, "User");
                        //if (RoleAddResult.Succeeded)
                        //{
                        //   // Success("User Added Successfuly!");
                        //    return Json(new { status = "ok" });
                        //}

                        //else
                        //{
                        //    return Json(new { status = "error",message= UserAddResult.Errors});
                        //}
                    }

                    else
                    {
                        return(Json(new { status = "error", message = UserAddResult.Errors }));
                    }
                }
                else
                {
                    return(Json(new { status = "error", message = new { text = "error" } }));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
 public SSOAuthUtil(ObjCacheProvider <UserAuthSession> objCacheProvider
                    , UserManagerApp userManager
                    , AppInfoService infoService)
 {
     _objCacheProvider = objCacheProvider;
     _userManager      = userManager;
     _appInfoService   = infoService;
 }
Exemplo n.º 6
0
 public AccountController(
     IIdentityServerInteractionService interaction,
     IClientStore clientStore,
     IAuthenticationSchemeProvider schemeProvider,
     IEventService events, UserManagerApp userManager)
 {
     _interaction    = interaction;
     _clientStore    = clientStore;
     _schemeProvider = schemeProvider;
     _events         = events;
     _userManager    = userManager;
 }
Exemplo n.º 7
0
        public async Task <ActionResult> Edit(string id)
        {
            UserApp user = await UserManagerApp.FindByIdAsync(id);

            if (user != null)
            {
                return(View(user));
            }
            else
            {
                ModelState.AddModelError("", "There Isn't any role like this id");
                return(View(new UserApp()));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Profile(UserApp user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (user.Id == User.Identity.GetUserId())
                    {
                        UserApp oldUser = await UserManagerApp.FindByIdAsync(user.Id);

                        if (oldUser != null)
                        {
                            oldUser.UserName    = user.UserName;
                            oldUser.Email       = user.Email;
                            oldUser.PhoneNumber = user.PhoneNumber;
                            IdentityResult result = await UserManagerApp.UpdateAsync(oldUser);

                            if (result.Succeeded)
                            {
                                // Success("User Updated", true);
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                // Danger("Failed! Something was wrong!");
                                result.Errors.ToList().ForEach(err => ModelState.AddModelError("", err));
                                return(View(user));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "There Isn't any role like this id");
                            return(View(new UserApp()));
                        }
                    }
                    // Danger("Failed! Something was wrong!");
                    return(View());
                }
                else
                {
                    // Warning("Model is not valid!");
                    return(View(user));
                }
            }
            catch (Exception)
            {
                //   Danger("Failed! Something was wrong!");
                throw;
            }
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Profile(string id)
        {
            try
            {
                if (id == User.Identity.GetUserId())
                {
                    UserApp user = await UserManagerApp.FindByIdAsync(id);

                    return(View(user));
                }

                // Danger("Failed! Something was wrong!");
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Index(IEnumerable <string> RoleName, string userid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    IEnumerable <string> rolenames         = RoleName ?? new List <string>();
                    IEnumerable <string> selectedRoleNames = rolenames;
                    // IEnumerable<string> unselectedRoleNAmes = Helper.GetRoles().Select(a => a.Name).Except(rolenames);

                    foreach (var role in selectedRoleNames.ToList())
                    {
                        if (!UserManagerApp.IsInRole(userid, role))
                        {
                            await UserManagerApp.AddToRoleAsync(userid, role);

                            // Success("User added to role" + role, true);
                        }
                    }

                    //foreach (var srole in unselectedRoleNAmes.ToList())
                    //{
                    //    if (UserManagerApp.IsInRole(userid, srole))
                    //    {
                    //        await UserManagerApp.RemoveFromRolesAsync(userid, srole);
                    //       // Success("User removed from role " + srole, true);
                    //    }
                    //}

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception)
            {
                //Danger("Somethings was wrong!", true);
                ModelState.AddModelError("", "Something was wrong");
                return(View());
            }
        }
Exemplo n.º 11
0
        public JsonResult Login(UserApp user, string password)
        {
            UserApp thisUser = UserManagerApp.Find(user.Email, password);

            if (thisUser != null)
            {
                ClaimsIdentity Ident = UserManagerApp.CreateIdentity(thisUser, DefaultAuthenticationTypes.ApplicationCookie);
                HttpContext.GetOwinContext().Authentication.SignOut();

                HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = false
                }, Ident);
                return(Json(new { status = "ok" }));
            }
            else
            {
                return(Json(new { status = "error" }));
            }
        }
Exemplo n.º 12
0
 public UserManagerController()
 {
     _app = AutofacExt.GetFromFac <UserManagerApp>();
 }
Exemplo n.º 13
0
 public TestUser()
 {
     _app = AutofacExt.GetFromFac <UserManagerApp>();
 }
Exemplo n.º 14
0
 public UsersController(UserManagerApp app)
 {
     _app = app;
 }
Exemplo n.º 15
0
 public DefaultController(UserManagerApp app)
 {
     MyProperty = app;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestUserProfileService"/> class.
 /// </summary>
 /// <param name="users">The users.</param>
 /// <param name="logger">The logger.</param>
 public CustomProfileService(ILogger <TestUserProfileService> logger, UserManagerApp userManager)
 {
     Logger      = logger;
     UserManager = userManager;
 }
Exemplo n.º 17
0
 public UserManagerController(IAuth authUtil, IHostingEnvironment hostingEnvironment, UserManagerApp app) : base(authUtil, hostingEnvironment)
 {
     _app = app;
 }
Exemplo n.º 18
0
 public ActionResult Detail(string id)
 {
     return(View(UserManagerApp.FindById(id)));
 }
 public UserManagerController(IAuth authUtil, UserManagerApp app) : base(authUtil)
 {
     _app = app;
 }
Exemplo n.º 20
0
 public FlowDesignController()
 {
     wfFlowInfoBLL = AutofacExt.GetFromFac <WFSchemeService>();
     userBLL       = AutofacExt.GetFromFac <UserManagerApp>();
 }