예제 #1
0
        public ApplicationUserIM Login(string email, string lozinka)
        {
            ApplicationUserIM retVal = new ApplicationUserIM();

            try
            {
                ApplicationUser user = userManager.FindByName(email);

                if (user != null && userManager.CheckPassword(user, lozinka))
                {
                    var roles = userManager.GetRoles(user.Id);
                    if (roles.Count > 0)
                    {
                        retVal.ime           = user.ime;
                        retVal.prezime       = user.prezime;
                        retVal.KorisnickoIme = user.UserName;
                        retVal.Uloga         = roles[0];
                        retVal.FirstLogin    = user.FirstLogin;
                    }
                }
            }catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(retVal);
        }
예제 #2
0
        public ApplicationUserIM GetUser(string kIme)
        {
            ApplicationUser   user   = userManager.FindByName(kIme);
            ApplicationUserIM retVal = new ApplicationUserIM()
            {
                ime           = user.ime,
                prezime       = user.prezime,
                KorisnickoIme = user.UserName,
                Uloga         = userManager.GetRoles(user.Id)[0]
            };

            return(retVal);
        }
예제 #3
0
        public bool ChangeUser(ApplicationUserIM user)
        {
            ApplicationUser toChange = userManager.FindByName(user.KorisnickoIme);

            if (toChange != null)
            {
                toChange.ime      = user.ime;
                toChange.prezime  = user.prezime;
                toChange.UserName = user.KorisnickoIme;


                var res = userManager.Update(toChange);
                return(res.Succeeded);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        public bool ChangePassword(ApplicationUserIM user, string novaLozinka)
        {
            ApplicationUser u = userManager.FindByName(user.KorisnickoIme);

            var provider = new DpapiDataProtectionProvider("AuthTesting");

            userManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser, string>(provider.Create("UserToken")) as IUserTokenProvider <ApplicationUser, string>;



            var token  = userManager.GeneratePasswordResetToken(u.Id);
            var result = userManager.ResetPassword(u.Id, token, novaLozinka);

            if (result.Succeeded)
            {
                u.FirstLogin = false;
                result       = userManager.Update(u);
            }

            return(result.Succeeded);
        }