Exemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] UserRegistrationDto data)
        {
            if (ModelState.IsValid)
            {
                var user = new Domain.Users.User
                {
                    UserName        = data.Email,
                    Email           = data.Email,
                    FirstName       = data.FirstName,
                    LastName        = data.LastName,
                    FacilityId      = data.FacilityId,
                    DoctorId        = data.DoctorId,
                    DateOfBirthsday = data.DateOfBirthsday,
                    Role            = data.Role
                };

                var result = await _userManager.CreateAsync(user, data.Password);

                if (result.Succeeded)
                {
                    return(Json(JsonResultData.Success()));
                }
            }

            return(Json(JsonResultData.Error("User already exists.")));
        }
Exemplo n.º 2
0
        public async Task <JsonResultData> Register([FromBody] UserRegistrationModel data)
        {
            if (ModelState.IsValid)
            {
                var user = new User
                {
                    UserName    = data.Email,
                    Email       = data.Email,
                    FirstName   = data.FirstName,
                    LastName    = data.LastName,
                    PhoneNumber = data.Phone,
                    Interests   = data.Interests,
                    Role        = Role.User
                };

                var result = await _userManager.CreateAsync(user, data.Password);

                if (result.Succeeded)
                {
                    return(JsonResultData.Success());
                }
            }

            return(JsonResultData.Error("ApiUser already exists."));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Login([FromBody] UserLoginDto model)
        {
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                var user  = _customerService.GetCustomerByTerm(model.Email);
                var token = GenerateToken(user);

                return(Json(new { user, token, tokenExpireData = DateTime.Now.AddDays(1) }));
            }

            return(Json(JsonResultData.Error("Username or password isn't correct.")));
        }
        public async Task <IActionResult> Register([FromBody] CustomerRegistrationDto data)
        {
            if (ModelState.IsValid)
            {
                var user = new Customer
                {
                    UserName        = data.Email,
                    Email           = data.Email,
                    FullName        = data.FullName,
                    DateOfBirthsday = data.DateOfBirthsday
                };

                var result = await _userManager.CreateAsync(user, data.Password);

                if (result.Succeeded)
                {
                    return(Json(JsonResultData.Success()));
                }
            }

            return(Json(JsonResultData.Error("User already exists.")));
        }
Exemplo n.º 5
0
        public async Task <JsonResultData> Login([FromBody] UserLoginModel model)
        {
            var result = await _signInManager
                         .PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                var user = await _customerService.GetUserByTermAsync(model.Email);

                var token = GenerateToken(user);

                var tokenResponse = new TokenResponseModel
                {
                    User        = user,
                    AccessToken = token,
                    ExpiresIn   = (int)TimeSpan.FromDays(1).TotalSeconds
                };

                return(JsonResultData.Success(tokenResponse));
            }

            return(JsonResultData.Error("Username or password isn't correct."));
        }