Пример #1
0
        public ActionResult SignUp(AccountSignUpViewModel model, bool? isdialog)
        {
            if (ModelState.IsValid)
            {
                var phone = UserService.NormalizePhoneNumber(model.PhoneNumber);

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

                var encryptedEmail = CryptographyService.EncryptEmail(model.Email);
                var usersWithSameEmail = DataService.PerThread.BaseUserSet.OfType<User>().Count(u => u.EncryptedEmail == encryptedEmail);
                if (usersWithSameEmail != 0)
                    throw new ValidationException("Пользователь с такой электропочтой уже зарегистрирован");

                var user = (User)AccountService.SignUp(model.Email, model.Email, model.Password, false);
                user.FirstName = model.Name;
                user.SurName = model.SurName;
                user.Patronymic = model.Patronymic;
                user.PhoneNumber = phone;
                user.Sex = ValueAnalizer.GetGenderFromString(model.Gender);
                user.IsPhoneVerified = false;
                user.IsEmailVerified = false;
                user.IsOutdated = true;

                UserService.NormalizePhoneNumber(user);

                if (model.ConnectSocial && HttpContext.Session["social_type"] != null && HttpContext.Session["social_id"] != null && HttpContext.Session["social_link"] != null)
                {
                    var socialType = (SocialType)HttpContext.Session["social_type"];
                    var socialLink = HttpContext.Session["social_link"].ToString();
                    var socialKey = HttpContext.Session["social_id"].ToString();

                    var usersWithSameSocial = DataService.PerThread.SocialAccountSet.Count(u => u.SocialId == socialKey && u.SocialType == (byte)socialType);
                    if (usersWithSameSocial != 0)
                        throw new ValidationException("Пользователь с таким аккаунтом " + model.SocialType.ToString() + " уже зарегистрирован");

                    AccountService.ConnectSocialAccount(user, socialType, socialLink, socialKey);
                    HttpContext.Session.Remove("social_id");
                    HttpContext.Session.Remove("social_type");
                    HttpContext.Session.Remove("social_link");
                }

                DataService.PerThread.SaveChanges();

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

                //var smtp = new SmtpClient();
                //var link = ConstHelper.AppUrl + Url.Action("codeVerification", new { id = user.Id });
                //var message = new MailMessage
                //{
                //    Subject = "Ввод кода подтверждения на Демократии2",
                //    Body = "<p>Если вы еще не ввели код подтверждения, пришедший вам по смс, перейдите по ссылке: <a href='" + link + "'>" + link + "</a>.</p>" +
                //        "<p>Если вам не пришло смс, напишите на <a href='mailto:[email protected]'>[email protected]</a></p>",
                //    IsBodyHtml = true
                //};

                //message.To.Add(user.Email);

                //smtp.Send(message);
                //smtp.Dispose();

                AccountService.SendEmailVerification(user.Id);
                AccountService.TrySignIn(model.Email, model.Password, true, HttpContext.Request.UserHostAddress);

                MonitoringService.AsynchLogUserRegistration(user.Id, HttpContext.Request.UserHostAddress);

                if (string.IsNullOrWhiteSpace(model.ReturnUrl))
                    return RedirectToAction("index", "user");

                return Redirect(model.ReturnUrl);
            }

            if (isdialog.HasValue)
                if (isdialog.Value)
                    return View("SignUp", "_LightLayout", model);

            return View(model);
        }
Пример #2
0
        public ActionResult SignUp(bool? isdialog, SocialType social = SocialType.None, string returnUrl = null)
        {
            var model = new AccountSignUpViewModel
            {
                SocialType = social,
                ConnectSocial = true,
                ReturnUrl = returnUrl
            };

            if (isdialog.HasValue)
                if (isdialog.Value)
                    return View("SignUp", "_LightLayout", model);

            return View(model);
        }