public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var kor = _context.Users.Add(new Domain.User { FirstName = request.FirstName, LastName = request.LastName, Password = request.Password, Email = request.Email }); kor.Context.SaveChanges(); _context.UserUserCase.Add(new Domain.UserUserCase { UserId = kor.Entity.Id, UseCaseId = 4 }); _context.UserUserCase.Add(new Domain.UserUserCase { UserId = kor.Entity.Id, UseCaseId = 5 }); _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfull registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterUserDto request) { validator.ValidateAndThrow(request); var user = mapper.Map <User>(request); user.Password = EasyEncryption.SHA.ComputeSHA256Hash(request.Password); context.Add(user); context.SaveChanges(); int id = user.Id; foreach (var uc in useCasesForUser) { context.UserUseCases.Add(new UserUseCases { UserId = id, UseCaseId = uc }); } context.SaveChanges(); email.Send(new SendEmailDto { Content = "<h2>Uspesno ste se registrovali. Arts Team</h2>", SendTo = request.Email, Subject = "Successful registration" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = EasyEncryption.SHA.ComputeSHA256Hash(request.Password), Email = request.Email }; _context.Users.Add(user); _context.SaveChanges(); int id = user.Id; foreach (var uc in useCasesForUser) { _context.UserUseCase.Add(new UserUseCase { UserId = id, UseCaseId = uc }); } _context.SaveChanges(); email.Send(new SendEmailDto { Content = "<h2> Successful registration to Blog </h2>", SendTo = request.Email, Subject = "Successful registration" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var useCases = _context.UseCases.Where(x => !x.AdminCase && x.Id != 8).Select(x => x.Id).ToList(); var user = _mapper.Map <WatchShop.Domain.User>(request); user.GroupId = 2; _context.Add(user); var listOfUseCases = new List <UserUserCase>(); foreach (var item in useCases) { listOfUseCases.Add(new UserUserCase { Id = user.Id, UseCaseId = item }); } user.UserUserCases = listOfUseCases; _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfull registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterDto request) { _validator.ValidateAndThrow(request); HashSet <UserUseCase> useCases = new HashSet <UserUseCase>(); foreach (var uucId in request.UseCasesIds) { var userUsecase = new UserUseCase { UserUseCaseId = uucId }; useCases.Add(userUsecase); } _context.Users.Add(new Domain.User { FirstName = request.FirstName, LastName = request.LastName, UserName = request.Username, Password = request.Password, Email = request.Email, UserUseCases = useCases }); _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfully registered!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = _mapper.Map <User>(request); _context.Users.Add(user); _context.SaveChanges(); int id = user.Id; List <int> listUseCases = new List <int> { 12, 16, 13, 8, 25, 9, 15, 14, 33, 34, 35, 36 }; foreach (int useCase in listUseCases) { _context.UserUseCases.Add(new UserUseCase { UserId = id, UseCaseId = useCase }); } _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfull registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = new Users() { FirstName = request.FirstName, LastName = request.LastName, UserName = request.UserName, Password = request.Password, Email = request.Email }; var model = new UserRoles() { RoleId = request.RoleId, UserId = user.Id }; user.UserRoles.Add(model); _context.Entry(model).State = EntityState.Added; _context.Entry(user).State = user.Id > 0 ? EntityState.Modified : EntityState.Added; _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfull registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterUserDto request) { var cases = new List <int> { 14, 19, 16 }; _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Password = request.Password, Username = request.Username }; _context.Users.Add(user); _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfuly registration</h1>", SendTo = request.Email, Subject = "Registration" }); foreach (var i in cases) { var userUseCase = new UserUseCase { UseCaseId = i, UserId = user.Id }; _context.Add(userUseCase); } _context.SaveChanges(); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = _mapper.Map <User>(request); user.RoleId = (int)Roles.User; _context.Users.Add(user); var useCases = new List <UserUserCase>(); foreach (var usecase in RightListes.UserRights()) { useCases.Add(new UserUserCase { Id = user.Id, UseCaseId = usecase }); } user.UserUserCases = useCases; _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Succesfull registration! </h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); _context.Users.Add(new Domain.User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = request.Password, Email = request.Email }); _context.SaveChanges(); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); // ValidationException var defaultUserRole = _context.Roles.Where(r => r.Name.Trim().ToLower() == "user").FirstOrDefault(); if (defaultUserRole == null) { defaultUserRole = _context.Roles.Where(r => r.RoleType == RoleType.User).OrderBy(r => r.Id).FirstOrDefault(); } var user = new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = request.Password, Email = request.Email, RoleId = defaultUserRole.Id, }; // if profile image is provided then upload image and set it for user if (request.ProfilePhoto != null) { var newFileName = Guid.NewGuid() + Path.GetExtension(request.ProfilePhoto.FileName); using (Image image = Image.Load(request.ProfilePhoto.OpenReadStream())) { image.Mutate(x => x.Resize(150, 150)); image.Save(Path.Combine("wwwroot", User.PofileImageFolderPath, newFileName)); } user.ProfilePhotoFileName = newFileName; } _context.Users.Add(user); _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successful registration!</h1><p>Welcome to Fotoblogger!</p>", SendTo = request.Email, Subject = "Registration - Fotoblogger" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Fullname = request.FirstName + " " + request.LastName, Username = request.Username, Password = request.Password, RoleId = 2, Email = request.Email }; _context.Users.Add(user); var useCases = new List <UserUseCase>(); var newUseCases = new List <int> { 4, 5, 9, 10, 14, 15, 19, 20, 24, 25, 26, 28, 35, 37 }; //ono sta sme ulogovani foreach (var useCase in newUseCases) { var userUseCases = new UserUseCase { UserId = user.Id, UseCaseId = useCase }; useCases.Add(userUseCases); } user.UserUseCases = useCases; _context.SaveChanges(); _sender.Send(new SendEmailDto { Subject = "Registration", Content = "<h1>Successfull registration, you can use your username and password to log in</h1>", SendTo = request.Email }); }
public async Task <IHttpActionResult> Register([FromBody] RegisterUser model) { var sb = new StringBuilder(Request.RequestUri.GetLeftPart(UriPartial.Authority)); sb.Append("/api/user/{0}/confirmemail/{1}"); //throws 400 var validator = new RegisterUserValidator(); validator.ValidateAndThrow(model); var(id, token) = await _service.RegisterAsync(model.Email, model.UserName, model.Password); if (id is null && token is null) { // throws 409 conflict throw new OperationCanceledException("Please provide unique UserName and Email."); } return(Ok(id)); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = request.Password, RoleId = 2, Email = request.Email }; _context.Users.Add(user); var list = new List <UserUseCase>(); var useCases = new List <int> { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; foreach (var useCase in useCases) { var userUseCase = new UserUseCase { UserId = user.Id, UseCaseId = useCase }; list.Add(userUseCase); } user.UserUseCases = list; _context.SaveChanges(); _sender.Send(new SendEmailDto { Subject = "Registration", Content = "<h1>Successfull registration, you can use your username and password to log in</h1>", SendTo = request.Email }); }
public void Execute(RegisterDto request) { var cases = new List <int> { 5, 8, 9, 16, 17, 18, 20, 23 }; _validator.ValidateAndThrow(request); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Email = request.Email, Password = request.Password //UserUseCases=useCases }; _context.Users.Add(user); _context.SaveChanges(); _sender.Send(new SendMailDto { Subject = "Registration", Content = "Successfully registration", SendTo = request.Email }); foreach (var i in cases) { var userUseCases = new UserUseCase { UseCaseId = i, UserId = user.Id }; _context.Add(userUseCases); } _context.SaveChanges(); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); _context.Users.Add(new User { FirstName = request.FirstName, LastName = request.LastName, Username = request.Username, Password = request.Password, Email = request.Email, RoleId = request.RoleId }); _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Successfull registration!</h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Izvrsi(RegisterUserDto request) { _validator.ValidateAndThrow(request); _context.Korisnici.Add(new Domain.Korisnik { Ime = request.Ime, Prezime = request.Prezime, KorisnickoIme = request.KorisnickoIme, Lozinka = request.Lozinka, Email = request.Email, GrupaId = request.GrupaId }); _context.SaveChanges(); _sender.Send(new PosaljiEmailDto { Sadrzaj = "Uspesna registracija", Kome = request.Email, Naslov = "Api registracija" }); }
public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); _context.Users.Include(x => x.UserUseCases); var user = _mapper.Map <User>(request); _context.Users.Add(user); _context.SaveChanges(); // --- OVAJ DEO --- int[] allowedUseCases = new int[] { 3, 6, 12, 13, 17, 18, 19, 20, 21 }; //var id = 1; foreach (var auc in allowedUseCases) { _context.UserUseCase.Add(new UserUseCase { //Id = id, UserId = user.Id, UseCaseId = auc }); //id++; } _context.SaveChanges(); _sender.Send(new SendEmailDto { Subject = "Registration", Content = "<h1>Successffully Registration</h1>", SendTo = request.Email }); }
public void Execute(UserDto request) { _validator.ValidateAndThrow(request); var md5 = MD5.Create(); byte[] passwordBytes = Encoding.ASCII.GetBytes(request.Password); byte[] hash = md5.ComputeHash(passwordBytes); var stringBuilder = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { stringBuilder.Append(hash[i].ToString("X2")); } var hashedPassword = stringBuilder.ToString(); var user = new User { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Username = request.Username, Password = hashedPassword }; _context.Users.Add(user); _context.SaveChanges(); var lastId = _context.Users.Max(u => u.Id); var currentUser = _context.Users.Find(lastId); //Lista slucajemo kojima korisnik moze da pristupi var userUseCases = new List <int> { 3, 6, 9, 11, 12, 14, 19, 20, 21, 25, 26 }; foreach (var cases in userUseCases) { _context.UserUseCases.Add( new UserUseCases { UserId = currentUser.Id, UseCaseId = cases } ); } _context.SaveChanges(); _email.Send(new EmailDto { EmailTo = request.Email, Subject = "Movie Plus Registration", Content = "<h1>You have successfully register.</h1>" }); }