public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("veysel"); if (adminUser == null) { await appUserService.Add(new AppUser() { FullName = "ahmet veysel bozoğlu", Password = "******", UserName = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("veysel"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppRoleService appRoleService, [FromServices] IAppUserRoleService appUserRoleService) { var appUser = await _appUserService.FindByUserNameAsync(appUserAddDto.UserName); if (appUser != null) { return(BadRequest($"{appUserAddDto.UserName} already exists")); } await _appUserService.InsertAsync(_mapper.Map <AppUser>(appUserAddDto)); var createdUser = await _appUserService.FindByUserNameAsync(appUserAddDto.UserName); var userRole = await appRoleService.FindByName(RoleInfo.Member); await appUserRoleService.InsertAsync(new AppUserRole { AppRoleId = userRole.Id, AppUserId = createdUser.Id }); return(Created("", appUserAddDto)); }
public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppUserRoleService appUserRoleService, [FromServices] IAppRoleService appRoleService) { var appUser = await _appUserService.FindByUserName(appUserAddDto.FullName); if (appUser != null) { return(BadRequest($"{appUserAddDto.UserName} zaten alınmış.")); } await _appUserService.Add(_mapper.Map <AppUser>(appUserAddDto)); var user = await _appUserService.FindByUserName(appUserAddDto.UserName); var role = await appRoleService.FindByName(RoleInfo.Member); await appUserRoleService.Add(new AppUserRole { AppRoleId = role.Id, AppUserId = user.Id }); return(Created("", appUserAddDto)); }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { //ilgili rol varmı? var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("sametirkoren"); if (adminUser == null) { await appUserService.Add(new AppUser { FullName = "Samet İrkören", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("sametirkoren"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public async static Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName("Admin"); var memberRole = await appRoleService.FindByName("Member"); if (adminRole == null) { await appRoleService.InsertAsync(new AppRole { Name = RoleInfo.Admin }); } if (memberRole == null) { await appRoleService.InsertAsync(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserNameAsync("pcparticle"); if (adminUser == null) { await appUserService.InsertAsync(new AppUser { FullName = "Erol Aksoy", Password = "******", UserName = "******" }); var admin = await appUserService.FindByUserNameAsync("pcparticle"); var role = await appRoleService.FindByName("Admin"); await appUserRoleService.InsertAsync(new AppUserRole { AppRoleId = role.Id, AppUserId = admin.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppRoleService appRoleService, IAppUserRoleService appUserRoleService) { //have a role var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("enesb"); if (adminUser == null) { await appUserService.Add(new AppUser { UserName = "******", FullName = "enes baysal", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("enesb"); await appUserRoleService.Add(new AppUserRole { AppRoleId = role.Id, AppUserId = admin.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("savas.ev"); if (adminUser == null) { await appUserService.Add(new AppUser { FullName = "Savaş Ev", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var user = await appUserService.FindByUserName("savas.ev"); await appUserRoleService.Add(new AppUserRole { AppUserId = user.Id, AppRoleId = role.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.AddAsync(new Entities.Concrete.AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (adminRole == null) { await appRoleService.AddAsync(new Entities.Concrete.AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("Uzay"); if (adminUser == null) { await appUserService.AddAsync(new AppUser { FullName = "Uzay KAHRAMAN", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("Uzay"); await appUserRoleService.AddAsync(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminnUser = await appUserService.FindByUserName("sercan"); if (adminnUser == null) { await appUserService.Add(new AppUser { FullName = "sercan fırtına", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("sercan"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
private static async Task <AppRole> CheckRole(IAppRoleService appRoleService, IGenericService <AppRole> roleService, string roleName) { AppRole role = await appRoleService.FindByName(roleName); if (role == null) { role = new AppRole() { Name = roleName }; await roleService.AddAsync(role); } return(role); }
public async Task <IActionResult> SignUp(AppUserAddFormDto appUserAddDto) { if (ModelState.IsValid) { AppUser appUser = await appUserService.FindByUserName(appUserAddDto.UserName); if (appUser != null) { logger.LogInformation($"{appUser.UserName} Kullanici adi zaten alınmış"); ModelState.AddModelError("", $"{appUser.UserName} kullanıcı adı zaten alınmış"); return(View(appUserAddDto)); } appUserAddDto.Password = ToPasswordRepository.PasswordCryptographyCombine(appUserAddDto.Password); appUser = mapper.Map <AppUser>(appUserAddDto); await userService.AddAsync(appUser); logger.LogInformation($"{appUser.UserName} Kullanici olusturuldu"); AppRole memberRole = await appRoleService.FindByName(RoleInfo.Member); await userRoleService.AddAsync(new UserRole() { AppRoleId = memberRole.Id, AppUserId = appUser.Id }); logger.LogInformation($"{appUser.UserName} Kullanicisina varsayilan rol bilgisi eklendi"); return(RedirectToAction("SignIn")); } else { logger.LogInformation("AppUserAddDto Not Valid"); ModelState.AddModelError("", "Lütfen gereken tüm alanları doldurunuz."); return(View(appUserAddDto)); } }
public async Task<IActionResult> Register(UserRegisterDto userRegisterDto) { List<ErrorModel> errorModels = new List<ErrorModel>(); var user = await _appUserService.FindByUserName(userRegisterDto.Username); if (user != null) { var error = new ErrorModel() { FieldName = "Username", Message = $"{userRegisterDto.Username} is already taken." }; errorModels.Add(error); var response = new ErrorResponse() { Errors = errorModels }; return BadRequest(response); } if (await _appUserService.GetByFilter(U => U.Email == userRegisterDto.Email) != null) { var error = new ErrorModel() { FieldName = "Email", Message = $"{userRegisterDto.Email} in use." }; errorModels.Add(error); var response = new ErrorResponse() { Errors = errorModels }; return BadRequest(response); } var profileImagePath = ""; if (userRegisterDto.ProfileImage != null) { if (userRegisterDto.ProfileImage.ContentType != "image/png") { var fileTypeNotValid = new ErrorModel() { FieldName = "ProfileImage", Message = "File content type must be image/png." }; errorModels.Add(fileTypeNotValid); var response = new ErrorResponse() { Errors = errorModels }; return BadRequest(response); } var ppPath = Path.Combine(_hostingEnvironment.WebRootPath, "profileimages"); var fileName = userRegisterDto.Username + "profileimage.png"; var filePath = Path.Combine(ppPath, fileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await userRegisterDto.ProfileImage.CopyToAsync(fileStream); } profileImagePath = "wwwroot/profileimages/" + fileName; } byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(userRegisterDto.Password, out passwordHash, out passwordSalt); await _appUserService.Add(new AppUser { Email = userRegisterDto.Email, PasswordHash = passwordHash, PasswordSalt = passwordSalt, ProfileImage = profileImagePath, Username = userRegisterDto.Username, Point = 0, Part = userRegisterDto.Part, Grade = userRegisterDto.Grade, AimUniversity = userRegisterDto.AimUniversity, FullName = userRegisterDto.FullName }); var userInDb = await _appUserService.FindByUserName(userRegisterDto.Username); var role = await _appRoleService.FindByName(RoleInfo.Student); await _appUserRoleService.Add(new AppUserRole() { AppUserId = userInDb.Id, AppRoleId = role.Id }); RegisterSuccessDto registerSuccessDto = new RegisterSuccessDto() { Email = userInDb.Email, Username = userInDb.Username, ProfileImage = userInDb.ProfileImage, FullName = userInDb.FullName, AimUniversity = userInDb.AimUniversity, Grade = userInDb.Grade, Part = userInDb.Part, Point = userInDb.Point }; return Ok(registerSuccessDto); }