public bool VerifyEmail([FromBody] string token)
        {
            try
            {
                string verifyToken = TokenManager.ValidateJwtToken(token);
                if (verifyToken == null)
                {
                    return(false);
                }
                var account = _context.userDBModels.SingleOrDefault(x => x.VeryficationToken == verifyToken);

                if (account == null)
                {
                    return(false);
                }
                account.IsVerify          = true;
                account.VeryficationToken = null;

                _context.userDBModels.Update(account);
                _context.SaveChanges();
                return(true);
            }
            catch (ApplicationException e)
            {
                throw new ApplicationException(e.Message);
            }
        }
        public IActionResult ResetPassword([FromBody] NewPassword newPassword)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var user = _context.userDBModels.FirstOrDefault(s => s.Email == newPassword.Email);

            if (user == null)
            {
                return(BadRequest(new { message = "Nie istnieje użytkownik o takim emailu" }));
            }
            user.ResetPasswordToken = TokenManager.RandomTokenString();

            string resetPasswordtoken = TokenManager.GenerateResetPassToken(user.ResetPasswordToken, user.Email);

            _context.userDBModels.Update(user);
            _context.SaveChanges();
            string message = $@"<p>Wysłano powiadomienie o zresetowaniu hasła</p>
                                <p>Kliknij link aby dokończyć resetowanie</p>
                             <p> <a href=""{ClientBaseUrl}new-password?token={resetPasswordtoken}""> link <a/> </p>";

            _mailService.SendMail(newPassword.Email, "Resetowanie Hasła", message);
            return(Ok(new { message = "Link do zresetowania hasło został wysłany na twój e-mail" }));
        }
示例#3
0
        public void RemoveRefreshTokens(int userID)
        {
            var rows = _context.refreshTokens.Where(x => x.UserID == userID).ToList();

            foreach (RefreshToken item in rows)
            {
                _context.refreshTokens.Remove(item);
            }
            _context.SaveChanges();
        }
示例#4
0
 public void SendCurrencyToDataBase(List <CurrencyDBModel> _listOfValue, CashDBContext _context)
 {
     if (!CheckDatabase(_context))
     {
         foreach (CurrencyDBModel cash in _listOfValue)
         {
             _context.cashDBModels.Add(cash);
         }
         _context.SaveChanges();
         SendTodayCurrencyToSubscribers(_context, _mailService, _listOfValue);
         CheckAndSendAlert(_context, _mailService, _listOfValue);
     }
 }
示例#5
0
 public IActionResult AddAlert([FromBody] Remainder remainder)
 {
     try
     {
         var user = _context.userDBModels.FirstOrDefault(s => s.ID == remainder.UserID);
         if (user != null)
         {
             _context.Remainders.Add(remainder);
             _context.SaveChanges();
             return(Ok(new { message = "Pomyślnie ustawiono alert" }));
         }
         return(BadRequest(new { message = "Nie udało się ustawić alertu, spróbuj ponownie" }));
     }
     catch (ApplicationException e)
     {
         _logger.LogError(e.Message);
         return(BadRequest(new { message = "Nie udało się ustawić alertu, spróbuj ponownie" }));
     }
 }
示例#6
0
        private void CheckAndSendAlert(CashDBContext _context, IMailService _mailService, List <CurrencyDBModel> listOfCash)
        {
            var alerts = _context.Remainders.ToList();

            foreach (Remainder item in alerts)
            {
                if (item.Price == "Less")
                {
                    CurrencyDBModel todayPrice = listOfCash.FirstOrDefault(s => s.Code == item.Code);
                    if (todayPrice != null)
                    {
                        if (item.BidPrice > todayPrice.BidPrice)
                        {
                            var user = _context.userDBModels.FirstOrDefault(s => s.ID == item.UserID);
                            if (user != null)
                            {
                                _mailService.SendMail(user.Email, "Alert kursu", MakeMessageForAlert(todayPrice.Code, "sprzedaży", todayPrice.BidPrice));
                            }
                        }
                    }
                }
                if (item.Price == "More")
                {
                    CurrencyDBModel todayPrice = listOfCash.FirstOrDefault(s => s.Code == item.Code);
                    if (todayPrice != null)
                    {
                        if (item.AskPrice < todayPrice.AskPrice)
                        {
                            var user = _context.userDBModels.FirstOrDefault(s => s.ID == item.UserID);
                            if (user != null)
                            {
                                _mailService.SendMail(user.Email, "Alert kursu", MakeMessageForAlert(todayPrice.Code, "kupna", todayPrice.AskPrice));
                            }
                        }
                    }
                }
                if (item.EndDateOfAlert < DateTime.Now)
                {
                    _context.Remove(item);
                    _context.SaveChanges();
                }
            }
        }