Ejemplo n.º 1
0
        public IActionResult GetUserByToken([FromBody] SvcData aTokenData)
        {
            if (aTokenData == null)
            {
                return(BadRequest());
            }
            var vUserID         = SvcUtils.GetUserIDFromToken(aTokenData.JwToken);
            var vValidatedToken = LoginRepo.GetUserByToken(vUserID, aTokenData.JwToken);

            if (vValidatedToken != null)
            {
                var vValidatedUser = UserRepo.GetSingle(vUserID);
                if (vValidatedUser == null)
                {
                    return(BadRequest("User Not Found"));
                }
                vValidatedUser.AccessToken  = aTokenData.JwToken;
                vValidatedUser.RefreshToken = aTokenData.JwToken;
                string  vRetData       = JsonSerializer.Serialize(vValidatedUser);
                string  sEncryptedData = AppEncrypt.EncryptText(vRetData);
                SvcData vReturnData    = new SvcData()
                {
                    ComplexData = sEncryptedData,
                    JwToken     = aTokenData.JwToken
                };
                return(Ok(vReturnData));
            }
            else
            {
                return(BadRequest("User Not Found"));
            }
        }
Ejemplo n.º 2
0
        public async Task <AppUser> LoginAsync(SvcData aLoginUser)
        {
            try
            {
                aLoginUser.LoginEmail = AppEncrypt.EncryptText(aLoginUser.LoginEmail);
                aLoginUser.LoginPass  = AppEncrypt.EncryptText(aLoginUser.LoginPass);
                string serializedUser = JsonSerializer.Serialize(aLoginUser);

                var vRequestMessage = new HttpRequestMessage(HttpMethod.Post, LoginSvcUrl)
                {
                    Content = new StringContent(serializedUser)
                };
                vRequestMessage.Content.Headers.ContentType
                    = new System.Net.Http.Headers.MediaTypeHeaderValue(AppConstants.JsonMediaTypeHeader);

                var vSvcResponse = await SvcClient.SendAsync(vRequestMessage);

                if (vSvcResponse.IsSuccessStatusCode)
                {
                    var vResponseBody = await vSvcResponse.Content.ReadAsStreamAsync();

                    SvcData vSvcRetObj = await JsonSerializer.DeserializeAsync <SvcData>(vResponseBody, JsonOptions);

                    string sDeCryptedUser = AppEncrypt.DecryptText(vSvcRetObj.ComplexData);
                    return(JsonSerializer.Deserialize <AppUser>(sDeCryptedUser, JsonOptions));
                }
                return(null);
            }
            catch (Exception)
            { throw; }
        }
Ejemplo n.º 3
0
        public async Task <AppUser> VerifyEmailAsync(SvcData aVerifyEmailData)
        {
            aVerifyEmailData.VerificationCode = AppEncrypt.EncryptText(aVerifyEmailData.VerificationCode);
            string serializedData = JsonSerializer.Serialize(aVerifyEmailData);

            var vRequestMessage = new HttpRequestMessage(HttpMethod.Post, VerifyEmailSvcUrl)
            {
                Content = new StringContent(serializedData)
            };

            vRequestMessage.Content.Headers.ContentType
                = new System.Net.Http.Headers.MediaTypeHeaderValue(AppConstants.JsonMediaTypeHeader);

            var vSvcResponse = await SvcClient.SendAsync(vRequestMessage);

            if (vSvcResponse.IsSuccessStatusCode)
            {
                var vResponseBody = await vSvcResponse.Content.ReadAsStreamAsync();

                SvcData vSvcRetObj = await JsonSerializer.DeserializeAsync <SvcData>(vResponseBody, JsonOptions);

                string sDeCryptedUser = AppEncrypt.DecryptText(vSvcRetObj.ComplexData);
                return(JsonSerializer.Deserialize <AppUser>(sDeCryptedUser, JsonOptions));
            }
            else
            {
                throw new Exception(await vSvcResponse.Content.ReadAsStringAsync());
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> UploadFile(string aRequestUri, TEntity aObj,
                                            Stream aFiles, string aFileName)
        {
            try
            {
                string sSerialisedObj = JsonSerializer.Serialize(aObj);
                var    vAccessToken   = await LocalStorageSvc.GetItemAsync <string>(AppConstants.AccessKey);

                var vAuthHeader = new AuthenticationHeaderValue(AppConstants.BearerKey, vAccessToken);
                ServiceClient.DefaultRequestHeaders.Authorization = vAuthHeader;
                sSerialisedObj = AppEncrypt.EncryptText(sSerialisedObj);
                var aInputData = new DocsWithFiles()
                {
                    ComplexData = sSerialisedObj,
                    DocFile     = aFiles
                };
                MultipartFormDataContent vMultiPartData = new MultipartFormDataContent();
                HttpContent vImageContent = new StreamContent(aInputData.DocFile);
                vImageContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name     = "DocFile",
                    FileName = aFileName
                };
                vImageContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                vMultiPartData.Add(vImageContent);
                vMultiPartData.Add(new StringContent(aInputData.ComplexData), "ComplexData");
                var vSvcResponse = await ServiceClient.PostAsync(aRequestUri, vMultiPartData);

                return(vSvcResponse.IsSuccessStatusCode);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
0
 public IActionResult AppLogin([FromBody] SvcData aLoginData)
 {
     if (aLoginData == null)
     {
         return(BadRequest());
     }
     try
     {
         string sJwToken;
         var    vEmail = AppEncrypt.DecryptText(aLoginData.LoginEmail);
         var    vPass  = AppEncrypt.DecryptText(aLoginData.LoginPass);
         vPass = AppEncrypt.CreateHash(vPass);
         var vValidatedUser = UserRepo.GetLoginUser(vEmail, vPass);
         if (vValidatedUser != null)
         {
             sJwToken = GenerateJWToken(vValidatedUser);
             var vUserLogins = new UserLogin()
             {
                 LoginToken  = sJwToken,
                 IssueDate   = DateTime.Today,
                 LoginDate   = DateTime.Today,
                 ExipryDate  = DateTime.Today.AddDays(2),
                 TokenStatus = TokenStatus.ValidToken.ToString(),
                 UserId      = vValidatedUser.AppUserId
             };
             LoginRepo.Insert(vUserLogins);
             vValidatedUser.AccessToken  = sJwToken;
             vValidatedUser.RefreshToken = sJwToken;
         }
         else
         {
             return(BadRequest("User Not Found"));
         }
         string  vRetData       = JsonSerializer.Serialize(vValidatedUser);
         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));
     }
 }
Ejemplo n.º 7
0
        public async Task <bool> ResendVerifiEmailAsync(SvcData aVerifiEmailData)
        {
            aVerifiEmailData.LoginEmail = AppEncrypt.EncryptText(aVerifiEmailData.LoginEmail);
            string serializedData = JsonSerializer.Serialize(aVerifiEmailData);

            var vRequestMessage = new HttpRequestMessage(HttpMethod.Post, ResendVerifiEmailSvcUrl)
            {
                Content = new StringContent(serializedData)
            };

            vRequestMessage.Content.Headers.ContentType
                = new System.Net.Http.Headers.MediaTypeHeaderValue(AppConstants.JsonMediaTypeHeader);

            var vSvcResponse = await SvcClient.SendAsync(vRequestMessage);

            return(vSvcResponse.IsSuccessStatusCode ? true : throw new Exception(await vSvcResponse.Content.ReadAsStringAsync()));
        }
Ejemplo n.º 8
0
        public IActionResult VerifyEmail([FromBody] SvcData aVerifyEmailData)
        {
            if (aVerifyEmailData == null)
            {
                return(BadRequest());
            }

            try
            {
                var vVerificationCode = AppEncrypt.DecryptText(aVerifyEmailData.VerificationCode);
                var vAppUser          = UserRepo.GetUserByVerificationCode(vVerificationCode);

                if (vAppUser == null)
                {
                    return(BadRequest("Invalid verification code."));
                }

                if (!vAppUser.IsVerified)
                {
                    vAppUser.IsVerified       = true;
                    vAppUser.VerificationCode = null;
                    UserRepo.Update(vAppUser);
                }

                var vRetData       = JsonSerializer.Serialize(vAppUser);
                var vEncryptedData = AppEncrypt.EncryptText(vRetData);
                var vReturnData    = new SvcData {
                    ComplexData = vEncryptedData
                };

                return(Ok(vReturnData));
            }
            catch (Exception ex)
            {
                AppLogger.LogCritical(ex.Message);
                return(BadRequest(ex));
            }
        }
Ejemplo n.º 9
0
        public async Task <AppUser> RegisterUserAsync(SvcData aLoginUser)
        {
            aLoginUser.ComplexData = AppEncrypt.EncryptText(aLoginUser.ComplexData);
            string serializedUser = JsonSerializer.Serialize(aLoginUser);

            var vRequestMessage = new HttpRequestMessage(HttpMethod.Post, RegSvcUrl)
            {
                Content = new StringContent(serializedUser)
            };

            vRequestMessage.Content.Headers.ContentType
                = new System.Net.Http.Headers.MediaTypeHeaderValue(AppConstants.JsonMediaTypeHeader);

            var vSvcResponse = await SvcClient.SendAsync(vRequestMessage);

            var vResponseBody = await vSvcResponse.Content.ReadAsStreamAsync();

            SvcData vSvcRetObj = await JsonSerializer.DeserializeAsync <SvcData>(vResponseBody, JsonOptions);

            string sDeCryptedUser = AppEncrypt.DecryptText(vSvcRetObj.ComplexData);

            return(JsonSerializer.Deserialize <AppUser>(sDeCryptedUser, JsonOptions));
        }
Ejemplo n.º 10
0
        public async Task <bool> RegisterUserAsync(SvcData aLoginUser)
        {
            aLoginUser.ComplexData = AppEncrypt.EncryptText(aLoginUser.ComplexData);
            string serializedUser = JsonSerializer.Serialize(aLoginUser);

            var vRequestMessage = new HttpRequestMessage(HttpMethod.Post, RegSvcUrl)
            {
                Content = new StringContent(serializedUser)
            };

            vRequestMessage.Content.Headers.ContentType
                = new System.Net.Http.Headers.MediaTypeHeaderValue(AppConstants.JsonMediaTypeHeader);

            var vSvcResponse = await SvcClient.SendAsync(vRequestMessage);

            if (vSvcResponse.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                throw new Exception(await vSvcResponse.Content.ReadAsStringAsync());
            }
        }