public AppUser Register(UserRegisterDto userRegisterDto) { HashingHelper.CreatePasswordHash(userRegisterDto.Password, out byte[] passwordHash, out byte[] passwordSalt); var newUser = new AppUser { TCNumber = userRegisterDto.TCNumber, Email = userRegisterDto.Email, FirstName = userRegisterDto.FirstName, LastName = userRegisterDto.LastName, PasswordSalt = passwordSalt, PasswordHash = passwordHash, }; //var claimUser = _appClaimService.GetClaim(AppClaimEnum.User.ToString()); var claimAdmin = _appClaimService.GetClaim(AppClaimEnum.Admin.ToString()); newUser.AppUserClaims.Add(new AppUserClaim { AppClaimId = claimAdmin.Id }); //newUser.AppUserClaims.Add(new AppUserClaim //{ // AppClaimId = claimAdmin.Id //}); _appUserService.Add(newUser); return(newUser); }
public ActionResult SignUp(AppUserForSignInVM appUserForSignInVM) { if (ModelState.IsValid) { AppUser appUser = new AppUser { AppUserId = appUserForSignInVM.AppUserId, FirstName = appUserForSignInVM.FirstName, LastName = appUserForSignInVM.LastName, UserName = appUserForSignInVM.UserName, Password = appUserForSignInVM.Password, Email = appUserForSignInVM.Email, }; if (_appUserService.Get(au => au.UserName == appUser.UserName) != null || _appUserService.Get(au => au.Email == appUser.Email) != null) { return(View(appUserForSignInVM)); } else { _appUserService.Add(appUser); return(RedirectToAction("SignIn")); } } else { return(View(appUserForSignInVM)); } }
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 IActionResult Add(UserDTO model) { if (ModelState.IsValid) { _userService.Add(model); return(RedirectToAction("GetList")); } return(View()); }
public async Task <IDataResult <AppUserOutput> > Register([FromBody] AppUserRegisterInput registerInput) { var result = await _appUserManager.Add(registerInput); if (!result.Success) { return(new ErrorDataResult <AppUserOutput>(result.Message)); } return(new SuccessDataResult <AppUserOutput>(result.Data, Messages.Successfully)); }
public IActionResult Post([FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest()); } var returnUser = _appUserService.Add(user); return(Ok(returnUser)); }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService , IAppRoleService appRoleService) { //Rol varsa eklemicem yoksa eklicem var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } //admin kullanıcı eklmedim. var adminUser = await appUserService.FindByUserNameAsync("ADMIN"); if (adminUser == null) { await appUserService.Add(new AppUser { UserName = "******", Password = "******" }); } //appuserrole tablosuna bu ilişkiyi eklemem lazım var role = await appRoleService.FindByNameAsync(RoleInfo.Admin); var admin = await appUserService.FindByUserNameAsync("ADMIN"); //daha önce eklenmiş mi var allUSerRole = await appUserRoleService.GetAll(); int kontrol = allUSerRole.Where(x => x.AppRoleId == role.Id && x.AppUserId == admin.Id).Count(); if (kontrol == 0) { await appUserRoleService.Add(new AppUserRole { AppRoleId = role.Id, AppUserId = admin.Id }); } }
public IActionResult Post([FromBody] AppUser newAppUser) { try { return(Ok(_appUserService.Add(newAppUser).ToApiModel())); } catch (Exception ex) { ModelState.AddModelError("AddAppUser", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Create([FromBody] CreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int userId = _service.Add(new AppUser { FirstName = model.FirstName, LastName = model.LastName }).ID; return(Ok(userId)); }
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 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) { //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 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 }); } }
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 IActionResult Create(AppUser user) { if (ModelState.IsValid) { if (user == null) { ViewBag.ErrorMessage = $"Please fill out all required fields"; } if (user != null) { _service.Add(user); } } else { return(RedirectToAction("create", "user")); } return(RedirectToAction("Index", "User")); }
public AppUser Register(UserRegisterDTO userRegisterDTO) { HashingHelper.CreatePasswordHash(userRegisterDTO.Password, out byte[] passwordHash, out byte[] passwordSalt); var newUser = new AppUser { TCNumber = userRegisterDTO.TCNumber, Email = userRegisterDTO.Email, FirstName = userRegisterDTO.FirstName, LastName = userRegisterDTO.LastName, PasswordSalt = passwordSalt, PasswordHash = passwordHash, }; if (userRegisterDTO.UserRole == 1) { var claim = _appClaimService.GetClaim(AppClaimEnum.Teacher.ToString()); newUser.AppUserClaims.Add(new AppUserClaim { AppClaimId = claim.Id }); } else if (userRegisterDTO.UserRole == 2) { var claim = _appClaimService.GetClaim(AppClaimEnum.Student.ToString()); newUser.AppUserClaims.Add(new AppUserClaim { AppClaimId = claim.Id }); } else if (userRegisterDTO.UserRole == 3) { var claim = _appClaimService.GetClaim(AppClaimEnum.Admin.ToString()); newUser.AppUserClaims.Add(new AppUserClaim { AppClaimId = claim.Id }); } _appUserService.Add(newUser); return(newUser); }
public ActionResult Register(AppUser item) { if (!ModelState.IsValid) { return(BadRequest()); } if (ModelState.IsValid) { if (_service.UsernameExisits(item)) { ViewBag.UserExists = "This user is already registered"; return(View()); } item.Password = Crypto.HashPassword(item.Password); _service.Add(item); return(RedirectToAction("index")); } return(RedirectToAction("index", "user")); }
public IActionResult Add(UserDto model) { _appUserService.Add(model); return(RedirectToAction("List")); }
public async Task <IActionResult> Create(AppUser appUser) { await _appUserService.Add(appUser); return(RedirectToAction("/Admin/AppUser/Index")); }
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); }