public ServiceResult CreateUser(ObjUser obj) { try { obj.Email = obj.Email.Trim(); var users = _userRepository.All(); if (users.Any(x => string.Equals(x.Email, obj.Email))) { return(ServiceResult.ErrorResult("Указанный Email уже зарегистрирован")); } obj.PassHash = HelperMd5.CalculateMD5Hash(obj.PassHash); //сохраняем аватар if (obj.file != null) { var originalName = obj.file.FileName.Trim(); var extension = Path.GetExtension(originalName); var fileName = Guid.NewGuid().ToString("N") + extension; var path = Path.Combine(CoreConfiguration.PathAvatar, fileName); _fileHelper.SaveFile(obj.file, path); obj.AvatarFileName = fileName; } var model = Map(obj); _userRepository.Insert(model); _userRepository.SaveChanges(); return(ServiceResult.SuccessResult(model.Id)); } catch (Exception ex) { //_logger.LogError("Error with Create User : {0}", ex.Message); return(ServiceResult.ErrorResult("Ошибка при создании новго пользователя")); } }
public ServiceResult ChangePassword(ObjChangePassword model) { try { var user = _userRepository.Get(model.Id); if (user == null) { return(ServiceResult.ErrorResult("Сотрудник не найден")); } user.PassHash = HelperMd5.CalculateMD5Hash(model.NewPassword); _userRepository.Update(user); _userRepository.SaveChanges(); return(ServiceResult.SuccessResult(user.Id)); } catch (Exception ex) { //_logger.LogError("Error with edit password for user id = {0} / message: {1}", model.Id, ex.Message); return(ServiceResult.ErrorResult("Ошибка при сохранении пароля")); } }
public ObjUser Login(string email, string pass) { if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(pass)) { return(null); } var passHash = HelperMd5.CalculateMD5Hash(pass); if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(passHash)) { return(null); } string lowerEmail = email.ToLower(); ObjUser model = null; var User = _userRepository.GetByEmailAndPassword(lowerEmail, passHash); model = Map(User); //_logger.LogInformation("Логин юзер"); return(model); }