Exemplo n.º 1
0
 public override void CreateRole(string roleName)
 {
     Роли role = new Роли() { НазваниеРоли = roleName };
     evrostroydbEntities context = new evrostroydbEntities();
     context.Роли.Add(role);
     context.SaveChanges();
 }
Exemplo n.º 2
0
 public override string[] GetRolesForUser(string username)
 {
     string[] role = new string[] { };
     using (evrostroydbEntities context = new evrostroydbEntities())
     {
         //получаем пользователя
        Пользователи user = context.Пользователи.Where(x => x.Email == username).FirstOrDefault();
         if (user != null)
         {
             //получаем роль
             Роли userrole = context.Роли.Find(user.ИдРоли);
             if (userrole != null)
             {
                 role = new string[] { userrole.НазваниеРоли };
             }
         }
     }
     return role;
 }
Exemplo n.º 3
0
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     LogImplemetation.ClassLog.Write("Попытка входа "+ model.NameIn);
     ViewBag.Rest = false;
     try {
         if (ModelState.IsValid)
         {//вызов метода удаления Log файлов каждый месяц 21 число
             DeleteLog();
             string g = "i";
             Пользователи us = null;
             using (evrostroydbEntities context = new evrostroydbEntities())
             {
                 us = context.Пользователи.FirstOrDefault(u => u.Email == model.NameIn && u.Пароль == model.PasswordIn);
             }
             if (us != null)
             {
                 FormsAuthentication.SetAuthCookie(us.Email, true);
                 Session["ИмяТекущегоПользователя"] = us.Имя;
                 if (returnUrl != "/")
                 {
                     return RedirectToLocal(returnUrl);
                 }
                 else
                 {
                     return RedirectToAction("MainPage", "Home");
                 }
             }
             else
             {
                 ViewBag.Rest = true;
                 ModelState.AddModelError("NameIn", "Пользователя с таким логином и паролем нет или не правильно введен логин и пароль");
             }
         }
         return View(model);
     }
     catch(Exception er)
     {
         LogImplemetation.ClassLog.Write("Ошибка при входе AccountController\\Login: "******"Exception");
     }
 }
Exemplo n.º 4
0
 public override bool IsUserInRole(string username, string roleName)
 {
     bool outputResult = false;
     using (evrostroydbEntities context = new evrostroydbEntities())
     {
         Пользователи user = context.Пользователи.Where(x => x.Email == username).FirstOrDefault();
         if (user != null)
         {
            Роли role = context.Роли.Find(user.ИдРоли);
             if (role != null && role.НазваниеРоли == roleName)
                 outputResult = true;
         }
     }
     return outputResult;
 }