示例#1
0
        public async Task <IActionResult> Register([FromBody] RegistrationRequest registration)
        {
            if (!registration.IsValid(DatabaseContext))
            {
                return(BadRequest(registration.Validate(DatabaseContext)));
            }

            var user = Map <User>(registration);

            user.RoleId = DatabaseContext.Roles.First(x => x.RoleName == "User").Id;
            await _authenticationService.AddUser(user);

            return(Ok(await _authenticationService.Authenticate(registration.GetEmail(), registration.Password)));
        }
示例#2
0
        public async Task <IActionResult> Register([FromBody] RegistrationRequest registration)
        {
            if (!registration.IsValid(DatabaseContext))
            {
                return(BadRequest(registration.Validate(DatabaseContext)));
            }

            var user = Map <User>(registration);

            user.EmailVerificationCode = Guid.NewGuid().ToString();
            await CreateEmail().SendEmailVerification(user.Email,
                                                      WebAppUrl + "/verify-email/" + user.EmailVerificationCode);

            await _authenticationService.AddUser(user);

            return(Ok(_authenticationService.Authenticate(registration.Email, registration.Password)));
        }
示例#3
0
 public ActionResult SignUp(SignUpModel login)
 {
     if (ModelState.IsValid)
     {
         if (_AuthenticationService.AddUser(login))
         {
             TempData["Success"] = "User Created Successfully !";
             return(RedirectToAction("Login", "Authentication"));
         }
         else
         {
             TempData["Error"] = "Could Not Create User Right Now Please Try Again Later.";
             return(View());
         };
     }
     else
     {
         TempData["Error"] = "Error Creating User. Please Check Your Details";
         return(View());
     }
 }
示例#4
0
        public async Task <IActionResult> CreateUser(RegistrationRequest userData)
        {
            if (!userData.IsValid(DatabaseContext))
            {
                return(BadRequest(userData.Validate(DatabaseContext)));
            }
            await DatabaseContext.Database.BeginTransactionAsync();

            var user = Map <User>(userData);

            user.Password = Guid.NewGuid().ToString();
            await _authenticationService.AddUser(user);

            user.SetNulls();
            await user.SetRole(DatabaseContext);

            await ResetUserPassword(user.Email);

            DatabaseContext.Database.CommitTransaction();
            return(Ok(user));
        }
 public bool AddUser(UserDataContract user)
 {
     return(_service.AddUser(user));
 }
示例#6
0
 public Task Post([FromBody] NewUserDto user)
 {
     return(_authenticationService.AddUser(user.Email, user.Password));
 }