Esempio n. 1
0
        public ActionResult Create(User user, string Password, string PasswordConfirm, FormCollection collection)
        {
            // Реп
            if (DataContext.Users.Any(u => u.Email.ToLower() == user.Email.ToLower()))
            {
                ShowError("Такой пользователь уже зарегистрирован");
                return(RedirectToAction("Index"));
            }

            // Регистрируем
            user.PasswordHash  = PasswordUtils.GenerateMD5PasswordHash(Password);
            user.DateRegistred = DateTime.Now;

            // Устанавливаем допуски для пользователя
            foreach (var projectId in collection.AllKeys.Where(k => k.StartsWith("project_")).Select(key => Convert.ToInt64(key.Split('_')[1])))
            {
                user.ProjectUsers.Add(new ProjectUser()
                {
                    ProjectId   = projectId,
                    User        = user,
                    DateCreated = DateTime.Now
                });
            }
            foreach (var warehouseId in collection.AllKeys.Where(k => k.StartsWith("warehouse_")).Select(key => Convert.ToInt64(key.Split('_')[1])))
            {
                user.WarehouseKeepers.Add(new WarehouseKeeper()
                {
                    WarehouseId = warehouseId,
                    User        = user,
                    DateCreated = DateTime.Now
                });
            }

            DataContext.Users.InsertOnSubmit(user);
            DataContext.SubmitChanges();

            ShowSuccess(string.Format("Успешно зарегистрирован пользователь {0} {1}. На его почту отправлено письмо с информацией о регистрации", user.GetFio(), user.Email));

            // Уведомляем
            var notificationModel = new
            {
                FIO      = user.GetFio(),
                Email    = user.Email,
                Password = Password
            };

            NotifyEmail(user, "Регистрация в системе LeadControl",
                        new ParametrizedFileTemplate(
                            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "Mail", "Register.html"),
                            notificationModel).ToString());

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 /// <summary>
 /// Возвращает урл аватарки
 /// </summary>
 /// <returns></returns>
 public string GetAvatar()
 {
     return(String.Format("http://www.gravatar.com/avatar/{0}?d=monsterid",
                          PasswordUtils.GenerateMD5PasswordHash(Email.Trim().ToLower()).ToLower()));
 }
Esempio n. 3
0
        public ActionResult Login(LoginModel model)
        {
            if (IsAuthentificated)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            // Валидируем что пользоатель есть
            var user = DataContext.Users.FirstOrDefault(u => u.Email.ToLower() == model.Email.ToLower() && u.PasswordHash == PasswordUtils.GenerateMD5PasswordHash(model.Password));

            if (user == null)
            {
                Locator.GetService <IUINotificationManager>().Error("Такой пользователь не найден");
                return(View(model));
            }

            // Авторизуем
            AuthorizeUser(user, model.RememberMe);
            user.LastLogin = DateTime.Now;
            DataContext.SubmitChanges();

            // Идем в личный кабинет
            return(RedirectToAction("Index", "Dashboard"));
        }