Пример #1
0
        public ActionResult ConfirmEmail(string key)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var repository = new ConfirmEmailRequestRepository(dataContext);

                var requests = repository._Get(u => u.RequestKey.Equals(key) && u.IsActive).ToList();

                if (requests.Any())
                {
                    var request = requests.FirstOrDefault();

                    if (request == null)
                    {
                        throw new Exception("Данного запроса не существует");
                    }

                    var userRepository = new ChatUserRepository(dataContext);
                    var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                    if (user == null)
                    {
                        throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                    }

                    user.Disabled = false;
                    userRepository._Update(user);
                    userRepository._Save();

                    request.IsActive = false;
                    repository._Update(request);
                    repository._Save();

                    return(View(new ConfirmEmailModel
                    {
                        RequestId = request.Id,
                        RequestKey = key,
                        UserDisplayName = user.Name
                    }));
                }
                else
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
            }
        }
Пример #2
0
        public string _GenerateConfirmLink(string login)
        {
            var receiverStrings = login.Split('@');
            var xmppLogin       = receiverStrings[0];

            using (var context = new InnostarModelsContext())
            {
                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.XmppLogin == xmppLogin).ToList();

                if (users.Any())
                {
                    var user = users.FirstOrDefault();

                    var confirmRepository = new ConfirmEmailRequestRepository(context);
                    var rnd        = new Random();
                    var requestKey = rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty)
                                     + rnd.Next(99).ToString(CultureInfo.InvariantCulture)
                                     + Guid.NewGuid().ToString().Replace("-", string.Empty);

                    //user.Disabled = true;
                    //repository._Update(user);
                    //repository._Save();

                    var request = new ConfirmEmailRequest
                    {
                        IsActive            = true,
                        RequestAcceptedTime = DateTime.Now,
                        RequestKey          = requestKey,
                        User = user
                    };

                    confirmRepository._Insert(request);
                    confirmRepository._Save();
                }
            }

            return(string.Empty);
        }