Beispiel #1
0
        public UserOut CreateAccount(UserRegister userRegister, bool isAdminAccount = false)
        {
            if (dataContext.Users.Any(x => x.Login == userRegister.Login))
            {
                throw new AppException("Podany login jest zajęty.");
            }

            if (dataContext.Users.Any(x => x.Email == userRegister.Email))
            {
                throw new AppException("Podany email jest zajęty.");
            }

            User user = mapper.Map <User>(userRegister);

            user.Roles = new List <string>();
            user.Roles.Add("User");

            if (isAdminAccount)
            {
                user.Roles.Add("Admin");
            }

            UserOut userOut = mapper.Map <UserOut>(dataContext.Users.Add(user).Entity);

            dataContext.SaveChanges();

            emailService.SendWelcomeMessage(user.Email);

            return(userOut);
        }
        public async Task <IActionResult> Signup([FromBody] SignupDTO userIn)
        {
            UserOut result = await authRepo.Register(userIn.email, userIn.username, userIn.password);

            if (result.success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public IActionResult Authenticate([FromBody] UserIn userParam)
        {
            UserOut authenticatedUser = userService.Authenticate(userParam);

            if (authenticatedUser == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(authenticatedUser));
        }
        public async Task <IActionResult> EmailLogin([FromBody] EmailLoginDTO userIn)
        {
            UserOut result = await authRepo.EmailLogin(userIn.email, userIn.password);

            if (!result.success)
            {
                return(BadRequest(result));
            }
            string token = JWTHelper.GenerateToken(result.email, result.username, secretKey, EXPIRE_TIME);

            Response.Cookies.Append(JWT_COOKIE_NAME, token, new Microsoft.AspNetCore.Http.CookieOptions
            {
                HttpOnly = true
            });
            return(Ok(result));
        }
Beispiel #5
0
 public Application(UserIn input, UserOut output)
 {
     this.input  = input;
     this.output = output;
 }
Beispiel #6
0
        public JsonResult GetAllUserList([FromBody] UserOut model)
        {
            var data = _userInfoAppService.GetAllUserList(model);

            return(Json(data));
        }