public async Task <ReqResult> CreateNewUser(SignupDTO newUserInfo)
        {
            var emailIsUsed = await _context.Users
                              .Where(user => user.email == newUserInfo.email)
                              .FirstOrDefaultAsync();

            if (emailIsUsed != null)
            {
                return(ReqResult.EmailInUse);
            }

            var newHash = BCrypt.Net.BCrypt.HashPassword(newUserInfo.password);

            var newUser = new NewUserDTO
            {
                email         = newUserInfo.email,
                first_name    = newUserInfo.first_name,
                last_name     = newUserInfo.last_name,
                password_hash = newHash
            };

            var dbInsertPayload = _mapper.Map <User>(newUser);

            await _context.AddAsync(dbInsertPayload);

            await _context.SaveChangesAsync();

            return(ReqResult.Ok);
        }
Example #2
0
        public List <SignupDTO> GetAllSignupClass(string _classId)
        {
            List <SignupDTO> listSignup = new List <SignupDTO>();

            this.ConnectToDatabase();

            MySqlCommand command = this.mySQLConnection.CreateCommand();

            command.CommandText = "SELECT * FROM SIGNUP where CLASS_ID = " + "'" + _classId + "'";

            MySqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string studentId = reader.GetString(0);
                string classId   = reader.GetString(1);
                string status    = reader.GetString(2);

                SignupDTO signup = new SignupDTO(studentId, classId, status);
                listSignup.Add(signup);
            }

            reader.Close();
            this.Close();
            return(listSignup);
        }
Example #3
0
        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 async Task <UnifyResponseDto> Post(SignupDTO model)
 {
     if (!string.IsNullOrWhiteSpace(model.Password))
     {
         if (await _service.CreateUserAsync(model))
         {
             return(UnifyResponseDto.Sucess("注册成功"));
         }
     }
     return(UnifyResponseDto.Fail());
 }
Example #5
0
        public async Task <ActionResult> CreateNewUser([FromBody] SignupDTO newUserInfo)
        {
            var result = await _repository.CreateNewUser(newUserInfo);

            if (result == ReqResult.Ok)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Example #6
0
        public bool InsertSignup(SignupDTO signup)
        {
            this.ConnectToDatabase();

            string Query = "insert into SIGNUP values('" + signup.StudentId + "','" + signup.ClassId + "','" + signup.Status + "');";

            //This is command class which will handle the query and connection object.
            MySqlCommand command = new MySqlCommand(Query, mySQLConnection);

            command.ExecuteNonQuery();

            this.Close();
            return(true);
        }
        public async Task <ActionResult <IdentityResult> > CreateEndUser(SignupDTO signupDTO)
        {
            EndUser user = new EndUser
            {
                UserName = signupDTO.Name,
                Email    = signupDTO.Email
            };
            var result = await _userManager.CreateAsync(user, signupDTO.Password);

            if (result.Succeeded)
            {
                return(Ok(returnRTO(user)));
            }
            return(BadRequest(result));
        }
Example #8
0
        public bool UpdateSignup(SignupDTO signup)
        {
            this.ConnectToDatabase();

            string Query = "update SIGNUP set STUDENT_ID='" + signup.StudentId + "',CLASS_ID = '" + signup.ClassId + "',STATUS = '" + signup.Status + "'";

            //This is command class which will handle the query and connection object.
            MySqlCommand command = new MySqlCommand(Query, mySQLConnection);

            command.ExecuteNonQuery();


            this.Close();
            return(true);
        }
Example #9
0
        public async Task <bool> CreateUserAsync(SignupDTO model)
        {
            User user   = _mapper.Map <SignupDTO, User>(model);
            bool result = false;

            if (model != null)
            {
                await _repository.InsertAsync(user);

                await _identitySvc.CreateUserIdentityAsync(IdentityType.Password, user.Id, model.Password);

                result = await _unitOfWork.CommitAsync();
            }
            return(result);
        }
        public async Task <IdentityResult> SignUp(SignupDTO signupUser)
        {
            var appUser = new ApplicationUser()
            {
                Email      = signupUser.Email,
                FirstName  = signupUser.FirstName,
                MiddleName = signupUser.MiddleName,
                LastName   = signupUser.LastName,
                UserName   = signupUser.UserName
            };
            IdentityResult result = await _userManager.CreateAsync(appUser, signupUser.Password);

            if (result.Succeeded)
            {
                result = await _userManager.AddToRoleAsync(appUser, "customer");
            }
            return(result);
        }
        public async Task <IActionResult> SignUp([FromBody] SignupDTO signupUser)
        {
            try
            {
                var result = await _authenticationService.SignUp(signupUser);

                if (result.Succeeded)
                {
                    return(Ok());
                }
                return(BadRequest(new { code = result.Errors.Select(err => err.Code), message = result.Errors.Select(err => err.Description) }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { code = new String[1] {
                                            "SystemError"
                                        }, message = new String[1] {
                                            ex.Message
                                        } }));
            }
        }
Example #12
0
        public async Task <IActionResult> Signup([FromBody] SignupDTO userIn)
        {
            logger.LogInformation("Username: "******"Email: " + userIn.email);
            logger.LogInformation(this.Request.ContentLength.ToString());
            InternalUser result = await authRepo.Register(userIn.email, userIn.username, userIn.password);

            if (result.success)
            {
                string token = JWTHelper.GenerateToken(result.email, result.username, SECRET_KEY, EXPIRE_TIME);
                return(Ok(new UserOutDTO
                {
                    Email = result.email,
                    Username = result.username,
                    JwtToken = token,
                    success = true
                }));
            }
            else
            {
                //No need to create a new UserOutDTO object, InternalUser doesn't contain any sensitive info
                return(BadRequest(result));
            }
        }