Exemplo n.º 1
0
        public IActionResult AppSignUp([FromBody] SvcData aSignUpData)
        {
            if (aSignUpData == null)
            {
                return(BadRequest());
            }
            try
            {
                string  sJwToken;
                var     vUserDataJson = AppEncrypt.DecryptText(aSignUpData.ComplexData);
                AppUser vNewUser      = JsonSerializer.Deserialize <AppUser>(vUserDataJson);

                var vCheckUserByEmail = UserRepo.GetUserByEmail(vNewUser.EmailID);
                if (vCheckUserByEmail != null)
                {
                    return(BadRequest("User with this Email already present use login or Forgot Password (if you had forgotten the password) "));
                }
                var vCheckUserByMobile = UserRepo.GetUserByMobile(vNewUser.MobileNo);
                if (vCheckUserByMobile != null)
                {
                    return(BadRequest("User with this Phone No already present use login or Forgot Password (if you had forgotten the password) "));
                }
                vNewUser.PasswordHash = AppEncrypt.CreateHash(vNewUser.PasswordHash);
                var iNewUserId = UserRepo.InsertToGetId(vNewUser);
                if (iNewUserId > 0)
                {
                    vNewUser.AppUserId = iNewUserId;
                    sJwToken           = GenerateJWToken(vNewUser);
                    var vUserLogins = new UserLogin()
                    {
                        LoginToken  = sJwToken,
                        IssueDate   = DateTime.Today,
                        LoginDate   = DateTime.Today,
                        ExipryDate  = DateTime.Today.AddDays(2),
                        TokenStatus = TokenStatus.ValidToken.ToString(),
                        UserId      = vNewUser.AppUserId
                    };
                    LoginRepo.Insert(vUserLogins);
                    vNewUser.AccessToken  = sJwToken;
                    vNewUser.RefreshToken = sJwToken;
                }
                else
                {
                    return(BadRequest("Unable to Save New User"));
                }
                string  vRetData       = JsonSerializer.Serialize(vNewUser);
                string  sEncryptedData = AppEncrypt.EncryptText(vRetData);
                SvcData vReturnData    = new SvcData()
                {
                    ComplexData = sEncryptedData,
                    JwToken     = sJwToken
                };
                return(Ok(vReturnData));
            }
            catch (Exception ex)
            {
                AppLogger.LogCritical(ex.Message);
                return(BadRequest(ex));
            }
        }
Exemplo n.º 2
0
        public IActionResult AppSignUp([FromBody] SvcData aSignUpData)
        {
            if (aSignUpData == null)
            {
                return(BadRequest());
            }
            try
            {
                var     vUserDataJson = AppEncrypt.DecryptText(aSignUpData.ComplexData);
                AppUser vNewUser      = JsonSerializer.Deserialize <AppUser>(vUserDataJson);

                var vCheckUserByEmail = UserRepo.GetUserByEmail(vNewUser.UserEmail);
                if (vCheckUserByEmail != null)
                {
                    return(BadRequest("User with this Email already present use login or Forgot Password (if you had forgotten the password) "));
                }
                var vCheckUserByMobile = UserRepo.GetUserByMobile(vNewUser.MobileNo);
                if (vCheckUserByMobile != null)
                {
                    return(BadRequest("User with this Phone No already present use login or Forgot Password (if you had forgotten the password) "));
                }
                vNewUser.PasswordHash = AppEncrypt.CreateHash(vNewUser.PasswordHash);
                vNewUser.UserRole     = AppConstants.AppUseRole;
                var vVerificationCode = $"{vNewUser.UserEmail}#{vNewUser.LastName}#{DateTime.UtcNow}";
                vNewUser.VerificationCode = AppEncrypt.CreateHash(vVerificationCode);
                var vNewUserId = UserRepo.InsertToGetId(vNewUser);
                if (vNewUserId > 0)
                {
                    vNewUser.AppUserId = vNewUserId;
                    SendVerificationEmail(vNewUser);
                }
                else
                {
                    return(BadRequest("Unable to Save New User"));
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                AppLogger.LogCritical(ex.Message);
                return(BadRequest(ex));
            }
        }