Exemplo n.º 1
0
        public async Task <dynamic> Register(string data)
        {
            string url    = $"{baseUrl}/Register";
            var    result = await _httpService.PostApiResult(url, KeyValuePair.Create(Rsa.PublicKey, RijndaelCrypt.EncryptString(data, Client.ServerKey, Client.ServerIV)));

            if (result.All(char.IsDigit))
            {
                return(JsonConvert.DeserializeObject <AuthorizeResultEnum>(result));
            }
            else
            {
                Client.AccessToken = RijndaelCrypt.DecryptString(JsonConvert.DeserializeObject <string>(result), Client.ServerKey, Client.ServerIV);
            }

            return(AuthorizeResultEnum.Ok);
        }
Exemplo n.º 2
0
        // GET: Auth/Verify
        public ActionResult Verify(string t)
        {
            try
            {
                AccountConfirmationInfo _accountConfirmation = null;

                string _token = RijndaelCrypt.DecryptString(t);

                using (AccountConfirmationRepository Repo = new AccountConfirmationRepository())
                {
                    _accountConfirmation = Repo.GetAccountConfirmationByToken(_token);
                }

                if (_accountConfirmation == null)
                {
                    TempData["Msg"] = "Link has been already used or invalid.";

                    return(View());
                    // invalid token
                }

                byte[]   data = Convert.FromBase64String(_token);
                DateTime when = DateTime.FromBinary(BitConverter.ToInt64(data, 0));

                if (when < DateTime.UtcNow.AddHours(-24))
                {
                    TempData["Msg"] = "Link has been expired.";

                    return(View());
                    // expired token
                }
                else
                {
                    TempData["AccountId"]  = _accountConfirmation.AccountId;
                    TempData["IsVerified"] = true;

                    return(RedirectToAction("ResetPassword"));
                    // valid token
                }
            }

            catch (Exception ex)
            {
                TempData["Msg"] = "<span style='color:red; text-align:center;'>" + ex.Message.ToString() + ".</span>";
                return(View());
            }
        }