public async Task <IActionResult> KayitOl(AppUserAddDto model) { if (ModelState.IsValid) { AppUser user = new AppUser() { UserName = model.UserName, Email = model.Email, Name = model.Name, Surname = model.Surname }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var addroleResult = await _userManager.AddToRoleAsync(user, "Member"); if (addroleResult.Succeeded) { return(RedirectToAction("Index")); } foreach (var item in result.Errors) { ModelState.AddModelError("", item.Description); } } foreach (var item in result.Errors) { ModelState.AddModelError("", item.Description); } } return(View(model)); }
public async Task <IActionResult> KayitOl(AppUserAddDto model) { if (ModelState.IsValid) { AppUser user = new AppUser() { UserName = model.UserName, Email = model.Email, Name = model.Name, Surname = model.Surname }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //bir rol ata var addroleResult = await _userManager.AddToRoleAsync(user, "Member"); if (addroleResult.Succeeded) { return(RedirectToAction("Index")); } HataEkle(addroleResult.Errors); } HataEkle(result.Errors); } return(View(model)); }
public async Task <IActionResult> Insert(AppUserAddDto model) { if (!ModelState.IsValid) { return(View(model)); } var obj = _mapper.Map <AppUser>(model); var result = await _userManager.CreateAsync(obj, model.Password); if (!result.Succeeded) { return(View(model)); } IEnumerable <string> data = new List <string> { "Administrator" }; var roleResult = await _userManager.AddToRolesAsync(obj, data); if (roleResult.Succeeded) { _customLogger.Information("UserController | Added New User : "******"Index")); } foreach (var item in roleResult.Errors) { _customLogger.Error("UserController | Insert User Error : " + obj.Email); ModelState.AddModelError("", item.Description); } return(View(model)); }
public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppUserRoleService appUserRoleService, [FromServices] IAppRoleService appRoleService) { appUserAddDto.Email = appUserAddDto.Email.ToLower(); appUserAddDto.UserName = appUserAddDto.UserName.ToLower(); var appUser = await _appUserService.FindByEmail(appUserAddDto.Email); if (appUser != null) { return(BadRequest(new { Error = $"{appUserAddDto.Email} alınmıştır. Farklı bir e-posta dene", ErrorType = "EMAIL_IS_ALREADY_IN_USE" })); } appUserAddDto.Password = BCrypt.Net.BCrypt.HashPassword(appUserAddDto.Password); appUserAddDto.ImagePath = "default.jpg"; await _appUserService.AddAsync(_mapper.Map <AppUser>(appUserAddDto)); var user = await _appUserService.FindByEmail(appUserAddDto.Email); var role = await appRoleService.FindByNameAsync(RoleInfo.Member); await appUserRoleService.AddAsync(new AppUserRole { AppRoleId = role.Id, AppUserId = user.Id }); var newUser = await _appUserService.FindByEmail(appUserAddDto.Email); var roles = await _appUserService.GetRolesByEmail(appUserAddDto.Email); var token = _jwtService.GenerateJwt(newUser, roles); return(Created("", new { token.Token, newUser.Id, expiresIn = 30 * 60 })); }
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 async System.Threading.Tasks.Task <IActionResult> SignUp(AppUserAddDto model) { if (ModelState.IsValid) { AppUser appUser = new AppUser() { UserName = model.UserName, Email = model.Email, Name = model.Name, Surname = model.Surname }; var result = await _userManager.CreateAsync(appUser, model.Password); if (result.Succeeded) { var roleResult = await _userManager.AddToRoleAsync(appUser, "Member"); if (roleResult.Succeeded) { return(RedirectToAction("Index")); } AddError(result.Errors); } AddError(result.Errors); } return(View()); }
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> Create(AppUserAddDto appUserAddDto) { if (ModelState.IsValid) { var result = await _appUserManager.Create(appUserAddDto); if (result == null) { return(RedirectToAction("Index")); } } return(View()); }
public async Task <AppUser> Create(AppUserAddDto appUserAddDto) { AppUser user = new AppUser { Email = appUserAddDto.Email, Name = appUserAddDto.Name, SurName = appUserAddDto.SurName, UserName = appUserAddDto.UserName, Password = appUserAddDto.Password, ConfirmPassword = appUserAddDto.ConfirmPassword }; var result = await _userManager.CreateAsync(user, appUserAddDto.Password); var addRoleResult = await _userManager.AddToRoleAsync(user, "Admin"); return(null); }
public async Task <IActionResult> KayitOl(AppUserAddDto model) { if (ModelState.IsValid) { AppUser user = new AppUser { UserName = model.UserName, Email = model.Email, Name = model.Name, Surname = model.Surname, }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var addRoleResult = await _userManager.AddToRoleAsync(user, "Member"); if (addRoleResult.Succeeded) { return(RedirectToAction("Index")); } HataEkle(addRoleResult.Errors); #region Silinen Kısım //foreach (var item in addRoleResult.Errors) //{ // ModelState.AddModelError("", item.Description); //} #endregion } HataEkle(result.Errors); #region Silinen Kısım //foreach (var item in result.Errors) //{ // ModelState.AddModelError("", item.Description); //} #endregion } return(View(model)); }
public async Task <IActionResult> Register(AppUserAddDto model) { if (ModelState.IsValid) { var user = _mapper.Map <AppUser>(model); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var addRoleResult = await _userManager.AddToRoleAsync(user, Roles.Member); if (addRoleResult.Succeeded) { return(RedirectToAction("Index")); } AddErrorRange(addRoleResult.Errors); } AddErrorRange(result.Errors); } return(View(model)); }
public async Task <IActionResult> Register([FromQuery] AppUserAddDto appUserAddDto, [FromServices] IAppUserRoleService appUserRoleService, [FromServices] IAppRoleService appRoleService) { var user = await this.appUserService.FindByUserNameAsync(appUserAddDto.Name); if (user != null) { return(BadRequest($"{appUserAddDto.UserName} is already registered in the system")); } await this.appUserService.Add(this.mapper.Map <AppUser>(appUserAddDto)); var appuser = await this.appUserService.FindByUserNameAsync(appUserAddDto.Name); var role = await appRoleService.FindByNameAsync(RoleInfo.Member); await appUserRoleService.Add(new AppUserRole { AppUserId = appuser.Id, AppRoleId = role.Id }); return(Created("", appUserAddDto)); }
private static async Task <AppUser> CheckUser(IAppUserService appUserService, IGenericService <AppUser> userService, AppUserAddDto appUserAddDto) { AppUser user = await appUserService.FindByUserName(appUserAddDto.UserName); if (user == null) { user = new AppUser() { UserName = appUserAddDto.UserName, FullName = appUserAddDto.FullName, Password = appUserAddDto.Password }; await userService.AddAsync(user); } return(user); }