コード例 #1
0
 public IActionResult OnPostSubmitAsync()
 {
     if (ModelState.IsValid)
     {
         try
         {
             user = _usercollection.Find(e => e.Email == Input.Email).FirstOrDefault();
         }
         catch (Exception e)
         {
             ModelState.AddModelError(string.Empty, "Please try again later.");
             _logger.LogError("ForgotPasswordError", e);
             return(Page());
         }
         if (user == null)
         {
             ModelState.AddModelError(string.Empty, "Please try again with correct credentials.");
             return(Page());
         }
         if (EmailCode != null && EmailCode.Equals(Input.Code))
         {
             TempData["Email"] = Input.Email;
             return(RedirectToPage("./ResetPassword"));
         }
         else
         {
             ModelState.AddModelError(string.Empty, "Code did not match. Please try again.");
             return(Page());
         }
     }
     return(Page());
 }
コード例 #2
0
        public ActionResult ConfirmEmail(int?ConfirmationCode)
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("Login", "Auth"));
            }

            if (isAdmin())
            {
                return(RedirectToAction("Index", "Admin"));
            }

            if (!isAdmin() && !isAuthor())
            {
                return(RedirectToAction("Logout", "Auth"));
            }

            Author author = authorHelper.GetById(GetAuthorId());

            if (author.isEmailConfirmed)
            {
                return(RedirectToAction("Index"));
            }

            ViewBag.Email = author.Email;

            if (ConfirmationCode == null)
            {
                ViewBag.Error = "Invalid confirmation code!";
                return(View());
            }

            if (ConfirmationCode.Value.ToString().Length != 6)
            {
                ViewBag.Error = "Invalid confirmation code!";
                return(View());
            }

            EmailCode emailCode = emailCodeHelper.GetAll().SingleOrDefault(e => e.AuthorId == author.Id && e.Email == author.Email && !e.isExpired);

            if (emailCode != null)
            {
                author.isEmailConfirmed = true;
                authorHelper.Update(author);

                emailCode.isExpired = true;
                emailCodeHelper.Update(emailCode);

                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Error = "Invalid confirmation code!";
            }

            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> Verify([FromBody] EmailCode emailCode)
        {
            string     email = emailCode.Email;
            string     code  = emailCode.Code;
            MobileUser user  = await UserDB.GetMobileUserByEmail(_context, email);

            if (user != null)
            {
                if (user.EmailCode == code)
                {
                    return(Ok(user.ApiKey));
                }
            }

            return(BadRequest());
        }
コード例 #4
0
        public async Task <IActionResult> SendDelete(string code)
        {
            // Redirects to index if code is null
            if (code == null)
            {
                return(Redirect("/"));
            }

            // Retrieves user and email and verified the correct user is signed in.
            User user = await _repository.GetUserAsync(User);

            EmailCode emailCode = await _repository.GetEmailCodeAsync(code);

            if (user != emailCode.User)
            {
                return(Forbid());
            }

            // Returns message if code is no longer valid
            MessageViewModel model;

            if (emailCode.ValidUntil < DateTime.Now)
            {
                model = new MessageViewModel()
                {
                    Title          = "Link expired",
                    MessageTitle   = "Account deletion link expired",
                    MessageContent = "To delete your account request another confirmation email"
                };
                return(View("Message", model));
            }

            // Removes account from database and signs out user
            user.Deleted = true;
            await _repository.SaveChangesAsync();

            await HttpContext.SignOutAsync();

            // Returns view
            model = new MessageViewModel()
            {
                Title        = "Account deleted",
                MessageTitle = "Account deleted"
            };
            return(View("Message", model));
        }
コード例 #5
0
        //Verification Email Services
        public EmailCode SelectById(int id)
        {
            EmailCode singleItem = new EmailCode();

            this.DataProvider.ExecuteCmd("dbo.EmailVerification_SelectByID"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@UserId", id);
            }
                                         , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                int startingIndex = 0;    //startingOrdinal

                singleItem.UserId = reader.GetSafeInt32(startingIndex++);
                singleItem.Code   = reader.GetSafeString(startingIndex++);
            });
            return(singleItem);
        }
コード例 #6
0
        public Client(Socket socket, Server server)
        {
            message   = new Message();
            userData  = new UserData();
            emailCode = new EmailCode();
            //userController = new UserController();
            codeData       = new CodeData();
            roleData       = new DAO.CharacterData();
            itemData       = new DAO.ItemData();
            friendData     = new DAO.FriendData();
            checkpointData = new DAO.CheckpointData();


            this.socket = socket;
            this.server = server;

            StartReceive();
        }
コード例 #7
0
        public async Task <IActionResult> ResetPassword(string code, int?error)
        {
            // Retrieves email code and redirects if null
            EmailCode emailCode = await _repository.GetEmailCodeAsync(code);

            if (emailCode == null)
            {
                return(Redirect("/"));
            }

            ResetPasswordViewModel model = new ResetPasswordViewModel()
            {
                Error  = error,
                Code   = code,
                UserID = emailCode.UserID
            };

            return(View(model));
        }
コード例 #8
0
        public async Task <IActionResult> GetEmail(EmailDto emailDto)
        {
            Random random = new Random();
            int    number = random.Next(100000, 999999);

            MailService.SendMail("Confirmation Mail", emailDto.Email, "Code: <br>" + number);
            var emailCode = new EmailCode()
            {
                Email = emailDto.Email,
                Code  = number
            };

            _authRepo.Add(emailCode);
            if (await _authRepo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to send the code"));
        }
コード例 #9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Email.Length != 0)
            {
                hash ^= Email.GetHashCode();
            }
            if (EmailCode.Length != 0)
            {
                hash ^= EmailCode.GetHashCode();
            }
            if (PhoneCode.Length != 0)
            {
                hash ^= PhoneCode.GetHashCode();
            }
            if (GoogleCode.Length != 0)
            {
                hash ^= GoogleCode.GetHashCode();
            }
            return(hash);
        }
コード例 #10
0
        public async Task <IActionResult> SendVerificationEmail([FromBody] EmailCode emailCode)
        {
            if (Utils.IsEmailValid(emailCode.Email))
            {
                string code = Utils.GenerateRandomCode();


                if (await UserDB.IsMobileUserExists(_context, emailCode.Email))
                {
                    MobileUser us = await UserDB.GetMobileUserByEmail(_context, emailCode.Email);

                    us.EmailCode = code;


                    User user = await UserDB.GetUserByEmail(_context, emailCode.Email);

                    if (user != null)
                    {
                        us.TelegramId = user.TelegramId;
                    }

                    _context.MobileUsers.Update(us);
                    _context.SaveChanges();
                }
                else
                {
                    UserDB.AddMobileUser(_context, emailCode.Email, code);
                }


                await Utils.SendEmailAsync(emailCode.Email, "Потверждение почты", $"Ваш кода для потверждения почты: {code}");

                return(Ok());
            }

            return(BadRequest());
        }
コード例 #11
0
 public ActionResult sendNewsletter(string message, string subject)
 {
     try
     {
         IEnumerable <User> response = userRepo.GetAllUsers().ToList();
         foreach (var item in response)
         {
             User user = new User();
             user.FirstName = "Admin";
             user.Roleid    = 2;
             user.Email     = "*****@*****.**";
             ViewBag.Status = item.Id;
             EmailCode.SendNewsLetter(user, item.Email, message, subject);
         }
         ViewBag.Status = "Done";
         return(View());
     }
     catch (Exception e)
     {
         ViewBag.Status = "Error";
         //   ViewBag.Status = e.Message.ToString();
     }
     return(View());
 }