//[AppAuthorize(PermissionTypes.Any, PermissionRule.update_user)]
        public async Task <IActionResult> Add([FromBody] AppUserlCreateViewMode Vm)
        {
            if (!ModelState.IsValid)
            {
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(new GenericResult(false, allErrors)));
            }
            else
            {
                try
                {
                    IdentityResult data = await _appUserService.AddAsync(Vm);

                    if (data.Succeeded)
                    {
                        return(new OkObjectResult(new GenericResult(true)));
                    }
                    else
                    {
                        return(new OkObjectResult(new GenericResult(false, data.Errors)));
                    }
                }
                catch (Exception ex)
                {
                    return(new OkObjectResult(new GenericResult(false, ex.Message)));
                }
            }
        }
        public async Task <IActionResult> SaveEntity(AppUserViewModel userVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            else
            {
                if (userVm.Id == null)
                {
                    var isValid = await _userService.AddAsync(userVm);

                    if (isValid == false)
                    {
                        return(new OkObjectResult(new GenericResult(false, userVm)));
                    }
                }
                else
                {
                    var isValid = await _userService.UpdateAsync(userVm);

                    if (isValid == false)
                    {
                        return(new OkObjectResult(new GenericResult(false, userVm)));
                    }
                }

                return(new OkObjectResult(new GenericResult(true, userVm)));
            }
        }
Esempio n. 3
0
        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 }));
        }
Esempio n. 4
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto,
                                                 [FromServices] IAppUserRoleService appUserRoleService,
                                                 [FromServices] IAppRoleService appRoleService)
        {
            var appUser = await _appUserService.FindByUserName
                              (appUserAddDto.UserName);

            if (appUser == null)
            {
                return(BadRequest($"{appUserAddDto.UserName} already taken"));
            }

            await _appUserService.AddAsync(_mapper.Map <AppUser>(appUserAddDto));

            var user = await _appUserService.FindByUserName(appUserAddDto.UserName);

            var role = await appRoleService.FindByName(RoleInfo.Member);

            await appUserRoleService.AddAsync(new AppUserRole
            {
                AppRoleId = role.Id,
                AppUserId = user.Id
            });

            return(Created("", appUserAddDto));
        }
Esempio n. 5
0
        public async Task <IActionResult> SignUp(SignUpModel model)
        {
            await _appUserService.AddAsync(new AppUser
            {
                Email    = model.Email,
                Password = model.Password,
                Username = model.Username
            });

            return(RedirectToAction("SignIn", "Home"));
        }
Esempio n. 6
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByEmail("*****@*****.**");

            if (adminUser == null)
            {
                string password = BCrypt.Net.BCrypt.HashPassword("1");

                await appUserService.AddAsync(new Entities.Concrete.AppUser
                {
                    Name      = "Admin Test",
                    Password  = password,
                    Email     = "*****@*****.**",
                    ImagePath = "default.jpg",
                    UserName  = "******",
                    Surname   = "Admin Surname",
                });


                var role = await appRoleService.FindByNameAsync(RoleInfo.Admin);

                var admin = await appUserService.FindByEmail("*****@*****.**");

                await appUserRoleService.AddAsync(new Entities.Concrete.AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.AddAsync(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserNameAsync("emre");

            if (adminUser == null)
            {
                await appUserService.AddAsync(new AppUser
                {
                    FullName = "emre yüksek",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByNameAsync(RoleInfo.Admin);

                var admin = await appUserService.FindByUserNameAsync("emre");

                await appUserRoleService.AddAsync(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
Esempio n. 8
0
        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
                });
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> Add([FromBody] AppUserViewModel Vm)
        {
            if (!ModelState.IsValid)
            {
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(new GenericResult(allErrors, false, ErrorMsg.DATA_REQUEST_IN_VALID, ErrorCode.ERROR_HANDLE_DATA)));
            }
            else
            {
                try
                {
                    var result = await _appUserService.AddAsync(Vm);

                    return(new OkObjectResult(new GenericResult(result, false, ErrorMsg.SUCCEED, ErrorCode.SUCCEED_CODE)));
                }
                catch (Exception ex)
                {
                    return(new OkObjectResult(new GenericResult(new AppUser(), false, ErrorMsg.HAS_ERROR, ErrorCode.HAS_ERROR_CODE)));
                }
            }
        }