示例#1
0
        public ActionResult CreatePetition(_CreatePetitionViewModel model)
        {
            if (!Request.IsAuthenticated)
            {
                throw new AuthenticationException();
            }

            if (ModelState.IsValid)
            {
                var data = new PetitionContainer
                {
                    GroupId   = model.GroupId,
                    IsPrivate = model.IsPrivate,
                    Tags      = model.TagTitles,
                    Text      = model.Text,
                    Title     = model.Title
                };

                var petition = VotingService.CreatePetition(data, UserContext.Current.Id);
                UserContext.Abandon();

                return(RedirectToAction("petition", petition.Controller, new { id = petition.Id }));
            }

            if (model.GroupId != null)
            {
                View("../group/createpetition", model);
            }

            return(View("../user/createpetition", model));
        }
        public void SignOut()
        {
            FormsAuthentication.SignOut();
            HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
            int sumCookie = cookies.Count;

            for (int i = 0; i < sumCookie; i++)
            {
                HttpCookie cookie = cookies[i];
                cookie.Expires = DateTime.Now.AddDays(-1);
                HttpContext.Current.Response.Cookies.Add(cookie);
            }

            UserContext.Abandon(); //Удалить текущий контекст пользователя
            HttpContext.Current.Session.Abandon();
        }
示例#3
0
        public ActionResult SignPetition(Guid id)
        {
            if (!Request.IsAuthenticated)
            {
                throw new AuthenticationException();
            }

            if (ModelState.IsValid)
            {
                Petition petition = VotingService.SignPetition(id, UserContext.Current.Id);
                UserContext.Abandon();
                return(RedirectToAction("petition", petition.Controller, new { id = petition.Id }));
            }

            return(Redirect(Request.UrlReferrer.PathAndQuery));
        }
示例#4
0
        public ActionResult SubscribeToGroup(string id)
        {
            if (!Request.IsAuthenticated)
            {
                throw new AuthenticationException();
            }

            SubscriptionService.SubscribeToGroup(id, UserContext.Current.Id);
            UserContext.Abandon();

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.PathAndQuery));
            }

            return(RedirectToAction("editsubscription", "user"));
        }
示例#5
0
 public ActionResult Logout()
 {
     UserContext.Abandon();
     return(RedirectToAction("Login"));
 }
示例#6
0
        public ActionResult Activation(AccountActivationViewModel model)
        {
            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("signin", "account", null));
            }

            if (ModelState.IsValid)
            {
                if (model.CodeId == Guid.Empty || string.IsNullOrWhiteSpace(model.Code))
                {
                    var phone = UserService.NormalizePhoneNumber(model.Phone);

                    var encryptedPhoneNumber = CryptographyService.EncryptPhone(phone);
                    var usersWithSamePhone   = DataService.PerThread.BaseUserSet.OfType <User>().Count(u => u.EncryptedPhoneNumber == encryptedPhoneNumber && (u.Id != model.Id));
                    if (usersWithSamePhone != 0)
                    {
                        throw new ValidationException("Пользователь с таким номером телефона уже активирован");
                    }

                    var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(u => u.Id == UserContext.Current.Id);
                    if (user == null)
                    {
                        throw new BusinessLogicException("Неверный идентификатор пользователя!");
                    }

                    user.PhoneNumber = phone;
                    user.SubscriptionSettings.SubscriptionEmail = model.SubscribtionMail;

                    UserService.NormalizePhoneNumber(user);

                    ModelState.Clear();

                    model.CodeId   = user.Id;
                    model.ShowCode = true;

                    var code = AccountService.GenerateSecretCode(user.Id);
                    var sms  = "Ваш секретный код для верификации на Демократии2: " + code;

                    if (UserContext.Current.SentSmsCount >= 5)
                    {
                        throw new BusinessLogicException("Лимит ваших смс исчерпан. Обратитесь в техподдержку");
                    }

                    SmsService.SendSms(user.PhoneNumber, sms);
                    UserContext.Current.SentSmsCount++;
                }
                else
                {
                    if (!AccountService.VerifySecretCode(model.CodeId, model.Code))
                    {
                        throw new ValidationException("Введен неверный код!");
                    }

                    if (UserContext.Current.Id != model.Id)
                    {
                        throw new BusinessLogicException("Возникла ошибка. Ключ пользователя начала и завершения активации аккаунта не совпадают.");
                    }

                    var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.Id == UserContext.Current.Id);
                    if (user == null)
                    {
                        throw new BusinessLogicException("Возникла ошибка. Система не знает такого пользователя.");
                    }

                    user.IsOutdated      = false;
                    user.IsPhoneVerified = true;

                    UserContext.Abandon();

                    return(RedirectToAction("profile", "user", null));
                }
            }

            return(View(model));
        }