Esempio n. 1
0
        public bool Delete(UserPasswords item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryUserPasswords.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                // Domain Services?
                //_repositoryUserPasswords.Delete(Mapper.Map<Dominio.Entidades.UserPasswords>(item));
                _repositoryUserPasswords.Delete(item);
                committed = _unitOfWorkAsync.SaveChanges();
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            return(committed > 0);
        }
Esempio n. 2
0
        public bool Register(Usuario item, string nomUsuario, string password)
        {
            Usuario       oUser     = new Usuario();
            UserPasswords oUserPass = new UserPasswords();
            Password      oPass     = new Password();

            return(true);
        }
Esempio n. 3
0
        // GET: Users/Edit/5
        public ActionResult Edit(int id)
        {
            UserModel     user          = dbContext.GetUserById(id);
            UserPasswords userPasswords = new UserPasswords
            {
                Id                   = user.Id,
                PasswordHash         = user.PasswordHash,
                IsPasswordKeptAsHash = user.IsPasswordKeptAsHash
            };

            return(View(userPasswords));
        }
Esempio n. 4
0
        async public Task <IActionResult> Put(string key, string values)
        {
            var user = _db.Users.First(a => a.Id == key);

            var oldRoles = _db.UserRoles.Where(s => s.UserId == key).ToList();

            JsonConvert.PopulateObject(values, user);
            var pwd = new UserPasswords();

            JsonConvert.PopulateObject(values, pwd);

            if (!TryValidateModel(user))
            {
                return(BadRequest(ModelState.GetFullErrorMessage()));
            }

            if (!pwd.Password.Equals(""))
            {
                if (!pwd.Password.Equals(pwd.ConfirmPassword))
                {
                    return(BadRequest("Password is not equal confirm password!"));
                }
                else
                {
                    String hashedNewPassword = _userManager.PasswordHasher.HashPassword(user, pwd.Password);
                    user.PasswordHash = hashedNewPassword;
                }
            }

            foreach (var role in oldRoles)
            {
                _db.UserRoles.Remove(role);
            }

            _db.SaveChanges();

            if (user.Roles != null)
            {
                foreach (var role in _db.Roles.ToList())
                {
                    if (user.Roles.Any(s => s.Id == role.Id))
                    {
                        var res = await _userManager.AddToRoleAsync(user, role.Name);
                    }
                }
            }

            _db.SaveChanges();

            return(Ok());
        }
        public JsonDocument ChangePassword(UserPasswords user)
        {
            var changed = new PKG_PROFILE().ChangePassword(authUser.ID, user.oldPassword, user.newPassword, user.confirmNewPassword);
            var status  = string.Empty;

            if (changed)
            {
                return(Success());
            }
            else
            {
                return(throwError("პაროლი ვერ შეიცვალა. გთხოვთ სწორად შეიყვანოთ არსებული პაროლი"));
            }
        }
Esempio n. 6
0
        public ActionResult Edit(int id, UserPasswords userPasswords)
        {
            try
            {
                UserModel users = dbContext.GetUserById(userPasswords.Id);

                UserModel editedUser = new UserModel
                {
                    Salt = GetSalt(),
                    Id   = userPasswords.Id,
                    IsPasswordKeptAsHash = userPasswords.IsPasswordKeptAsHash
                };

                string oldPassHash = users.IsPasswordKeptAsHash ?
                                     GetPasswordHashSHA512(userPasswords.OldPassword, users.Salt, pepper) :
                                     GetPasswordHMAC(userPasswords.OldPassword, users.Salt, pepper);

                if (users.PasswordHash == oldPassHash)
                {
                    editedUser.PasswordHash = userPasswords.IsPasswordKeptAsHash ?
                                              GetPasswordHashSHA512(userPasswords.NewPassword, editedUser.Salt, pepper) :
                                              GetPasswordHMAC(userPasswords.NewPassword, editedUser.Salt, pepper);

                    this.UpdateUserPasswords(editedUser, userPasswords.OldPassword, userPasswords.NewPassword);

                    dbContext.UpdateUser(editedUser);

                    return(RedirectToAction(nameof(Index)));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 7
0
        public bool Update(UserPasswords item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryUserPasswords.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                var validator = EntityValidatorFactory.CreateValidator();
                if (validator.IsValid(item))
                {
                    // Domain Services?
                    //_repositoryUserPasswords.Update(Mapper.Map<Dominio.Entidades.UserPasswords>(item));
                    _repositoryUserPasswords.Update(item);
                    committed = _unitOfWorkAsync.SaveChanges();
                }
                else
                {
                    throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            //_repositoryUserPasswords.Update(entity);
            return(committed > 0);
        }
Esempio n. 8
0
        //public async Task<ActionResult> Register(RegisterViewModel model)
        public ActionResult Register(RegisterViewModel model)
        {
            bool committed;

            if (ModelState.IsValid)
            {
                Usuario               oUser       = new Usuario();
                UserPasswords         oUserPass   = new UserPasswords();
                IList <UserPasswords> lstUserPass = new List <UserPasswords>();
                Password              oPass       = new Password();

                //Usuario
                //Password
                //string _srtEncrypt = desHelper.EncryptString(model.Password);
                //string _strDecrypt = desHelper.DecryptString("39S4D8vXqfk=");
                //oPass.PasswordHash = _srtEncrypt;
                //lstPass.Add(oPass);

                //Passwords de Usuario
                oPass.Password1    = model.Password;
                oUserPass.Password = oPass;
                lstUserPass.Add(oUserPass);

                //Usuario
                oUser.AccountName   = model.Email;
                oUser.UserPasswords = lstUserPass;
                committed           = _serviceUsuario.Insert(oUser, null);
                if (committed)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                //_servicePassword.Insert(oPass, null);
                //committed = _serviceUserPasswords.Insert(oUserPass, null);
                //_unitOfWork.SaveChanges();

                //return RedirectToAction("Index", "Home");

                //if (committed)
                //{
                //    if (committed)
                //    {
                //    }

                //}

                //var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
                //IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                //if (result.Succeeded)
                //{
                //    //await SignInAsync(user, isPersistent: false);

                //    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //    // Send an email with this link
                //    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                //    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                //    return RedirectToAction("Index", "Home");
                //}
                //else
                //{
                //    //AddErrors(result);
                //}
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 9
0
        public bool Insert(Usuario item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var           committed = 0;
            bool          result    = false;
            UserPasswords oUserPass = new UserPasswords();
            Password      oPass     = new Password();

            try
            {
                //if (session != null)
                //    _repositoryUsuario.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                var validator = EntityValidatorFactory.CreateValidator();
                if (validator.IsValid(item))
                {
                    var _repoPass     = _repositoryUsuario.GetRepository <Password>();
                    var _repoUserPass = _repositoryUsuario.GetRepository <UserPasswords>();

                    _unitOfWorkAsync.BeginTransaction();

                    oUserPass = item.UserPasswords.FirstOrDefault();
                    oPass     = oUserPass.Password;
                    //oUserPass = item.UserPasswords.FirstOrDefault();
                    //Password
                    string _srtEncrypt = desHelper.EncryptString(oPass.Password1);
                    //string _strDecrypt = desHelper.DecryptString("39S4D8vXqfk=");
                    //oPass.Password1 = item..Password;
                    oPass.PasswordHash  = _srtEncrypt;
                    oPass.TrackingState = TrackingState.Added;
                    ////////_repoPass.Insert(oPass);
                    //committed = _unitOfWorkAsync.SaveChanges();
                    //var oPassTemp = _repoPass.Queryable().Where(x => x.PasswordHash == _srtEncrypt).FirstOrDefault();

                    item.TrackingState = TrackingState.Added;
                    _repositoryUsuario.Insert(item, false);
                    //var oUser = _repositoryUsuario.Queryable().Where(x => x.AccountName == item.AccountName).FirstOrDefault();
                    //committed = _unitOfWorkAsync.SaveChanges();

                    oUserPass.IdUsuario     = item.Id;
                    oUserPass.IdPassword    = oPass.Id;
                    oUserPass.TrackingState = TrackingState.Added;
                    //_repoUserPass.Insert(oUserPass);

                    committed = _unitOfWorkAsync.SaveChanges();
                    result    = _unitOfWorkAsync.Commit();

                    // Domain Services?
                    //_repositoryUsuario.Insert(Mapper.Map<Dominio.Entidades.Usuario>(item));
                    //_repositoryUsuario.Insert(item);
                }
                else
                {
                    throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item));
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkAsync.Rollback();
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            //return committed > 0;
            return(result);
        }
Esempio n. 10
0
 public void ApplyChanges(UserPasswords entity)
 {
     _repositoryUserPasswords.ApplyChanges(entity);
 }
Esempio n. 11
0
 public UserPasswordsCrudViewModel()
 {
     UserPasswords = new UserPasswords();
 }