Ejemplo n.º 1
0
        public async Task <IActionResult> DirectSignUpWithEmail([FromBody] SignUpWithEmailViewModel model)
        {
            var checkemail = await _userManager.FindByEmailAsync(model.Email);

            if (string.IsNullOrEmpty(checkemail?.Email))
            {
                var currentUser = new ApplicationUser
                {
                    Email    = model.Email,
                    UserName = model.Email
                };

                /*
                 * var result = await _userManager.CreateAsync(currentUser);
                 * if (result.Succeeded)
                 * {
                 *  // Add to roles
                 *  var roleAddResult = await _userManager.AddToRoleAsync(currentUser, "User");
                 *
                 *  if (roleAddResult.Succeeded)
                 *  {
                 *      string ctoken = _userManager.GenerateEmailConfirmationTokenAsync(currentUser).Result;
                 *      string ctokenlink = Url.Action("ConfirmEmail", "Account", new
                 *      {
                 *          userId = currentUser.Id,
                 *          emailConfirmCode = ctoken
                 *      }, protocol: HttpContext.Request.Scheme);
                 *
                 *      var confirmationLink = "<a class='btn-primary' href=\"" + ctokenlink + "\">Confirm email address</a>";
                 *      _logger.LogInformation(3, "User created a new account with password.");
                 *      await _emailSender.SendEmailAsync(model.Email, "Registration confirmation email", confirmationLink);
                 *
                 *      SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();
                 *      response.ReturnCode = 200;
                 *      response.StatusMessage = "Success";
                 *      response.StatusCode = 200;
                 *      response.ReturnMsg = "Your account has been created, <br /> please verify it by clicking the activation link that has been send to your email.";
                 *
                 *      return Ok(response);
                 *  }
                 * }
                 * AddErrors(result);
                 */

                SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();
                response.ReturnCode    = 200;
                response.StatusMessage = "Success";
                response.StatusCode    = 200;
                response.ReturnMsg     = "Your account has been created, <br /> please verify it by clicking the activation link that has been send to your email.";

                return(Ok(response));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "This email is already registered.");
                return(BadRequest(new ApiError(ModelState)));
            }
            // If we got this far, something failed, redisplay form
            return(BadRequest(new ApiError(ModelState)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Authentication2FA(TwoFactorAuthViewModel model)
        {
            if (model != null)
            {
                SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();
                response.ReturnCode    = 200;
                response.ReturnMsg     = "Success";
                response.StatusCode    = 200;
                response.StatusMessage = "Done";
                return(Ok(response));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Invalid");
                return(BadRequest(new ApiError(ModelState)));
            }

            //var user = await GetCurrentUserAsync();

            //var model = new TwoFactorAuthenticationViewModel
            //{
            //    HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null,
            //    Is2faEnabled = user.TwoFactorEnabled,
            //    RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user),
            //};

            //return Ok(model);
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> DirectSignUpOtpVerification([FromBody] OTPViewModel model)
 {
     if (model != null)
     {
         SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();
         response.ReturnCode    = 200;
         response.ReturnMsg     = "Success";
         response.StatusCode    = 200;
         response.StatusMessage = "Done";
         return(Ok(response));
     }
     else
     {
         ModelState.AddModelError(string.Empty, "Invalid OTP.");
         return(BadRequest(new ApiError(ModelState)));
     }
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> DirectSignUpWithMobile([FromBody] SignUpWithMobileViewModel model)
        {
            SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();

            PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();

            string countryCode = "IN";

            PhoneNumbers.PhoneNumber phoneNumber = phoneUtil.Parse(model.Mobile, countryCode);


            bool isValidNumber = phoneUtil.IsValidNumber(phoneNumber); // returns true for valid number

            if (!isValidNumber)
            {
                response.ReturnCode    = 200;
                response.ReturnMsg     = "This mobile number is not Valid";
                response.ErrorCode     = 401;
                response.StatusCode    = 200;
                response.StatusMessage = "error";
                return(Ok(response));
                //   return Ok("This mobile number is  Valid");
            }



            bool IsSignMobile = _userdata.GetMobileNumber(model.Mobile);

            if (IsSignMobile)
            {
                /*
                 * var currentUser = new ApplicationUser
                 * {
                 *  Mobile = model.Mobile,
                 *  UserName = model.Mobile,
                 *  OTP = _userdata.GenerateRandomOTP()
                 * };
                 *
                 * var result = await _userManager.CreateAsync(currentUser);
                 * if (result.Succeeded)
                 * {
                 *  var officeClaim = new Claim(OpenIdConnectConstants.Claims.PhoneNumber, currentUser.Mobile, ClaimValueTypes.Integer);
                 *  await _userManager.AddClaimAsync(currentUser, officeClaim);
                 *  // Add to roles
                 *  var roleAddResult = await _userManager.AddToRoleAsync(currentUser, "User");
                 *
                 *  if (roleAddResult.Succeeded)
                 *  {
                 *      //await _messageSender.SendSMSAsync(model.Mobile, "");
                 *      SignUpMobileWithOTPResponse response = new SignUpMobileWithOTPResponse();
                 *      response.ReturnCode = 200;
                 *      response.ReturnMsg = "Success";
                 *      response.StatusCode = 200;
                 *      response.StatusMessage = "Done";
                 *      return Ok(response);
                 *  }
                 * }
                 * AddErrors(result);
                 */
                response.ReturnCode    = 200;
                response.ReturnMsg     = "Success";
                response.StatusCode    = 200;
                response.StatusMessage = "Done";
                return(Ok(response));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "This mobile number is already registered.");
                return(BadRequest(new ApiError(ModelState)));
            }
            // If we got this far, something failed, redisplay form
            return(BadRequest(new ApiError(ModelState)));
        }