示例#1
0
 public bool CheckifAccountisAdmin(AccountLoginModel model)
 {
     if (model.Username == "Edalzebu")
         return true;
     var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model);
     return account.IsAdmin;
 }
示例#2
0
 //Aux functions
 public bool CheckAuthCredentials(AccountLoginModel model)
 {
     var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model);
     if (account != null)
         return account.Password == Md5Encryption.Encriptar(model.Password);
     return false;
 }
示例#3
0
        public ActionResult Login(AccountLoginModel model)
        {
            var roles = new List<string>();
            if (CheckifAccountExists(model))
            {
                if (CheckAuthCredentials(model))
                {
                    if (CheckifAccountisAdmin(model))
                    {
                        roles.Add("Admin");
                    }
                    else
                    {
                        roles.Add("User");
                    }
                    FormsAuthentication.SetAuthCookie(model.Username, false);
                    SetAuthenticationCookie(model.Username, roles);
                    return RedirectToAction("Index", "Public");
                }
                else
                {
                    Error("Incorrect password for this username.");
                }
            }
            else
            {
                Error("That username doesnt exists on our database.");
            }

            return View(new AccountLoginModel());
        }
示例#4
0
 public bool CheckifAccountExists(AccountLoginModel model)
 {
     var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model);
     return account != null;
 }
示例#5
0
 public ActionResult ShowToolbar()
 {
     var model = new ShowToolbarModel();
     var modelo = new AccountLoginModel();
     modelo.Username = User.Identity.Name;
     var account = ReturnAccountIfUsernameExists(modelo) ?? ReturnAccountIfEmailExists(modelo);
     model.Username = account == null ? "" : account.Username;
     if (User.IsInRole("Admin"))
     {
         model.IsAdmin = true;
         model.IsUser = true;
     }
     else if (User.IsInRole("User"))
     {
         model.IsAdmin = false;
         model.IsUser = true;
     }
     return PartialView(model);
 }
示例#6
0
 public Account ReturnAccountIfUsernameExists(AccountLoginModel model)
 {
     var account = _readOnlyRepository.First<Account>(x => x.Username == model.Username);
     return account;
 }