Пример #1
0
        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)
        {
            //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
                });
            }
        }
Пример #3
0
        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
                });
            }
        }
Пример #4
0
        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, 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
                });
            }
        }
Пример #6
0
        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
                });
            }
        }
Пример #7
0
        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
                });
            }
        }
Пример #8
0
        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));
        }
Пример #9
0
        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);
        }