public ActionResult LogOn(AccountModel accountModel) { var adm = AccountDataMapper.GetAccountDataMapper(); var user = adm.GetById(accountModel.Username.ToLower()); if (user != null) { if (!user.Confirmed) { ModelState.AddModelError("Username", "O username inserido ainda não foi confirmado. Por favor confirme através do seu email."); } else if (LoginUtils.ComparePasswords(accountModel.Password, user)) { FormsAuthentication.SetAuthCookie(user.Username, false); return(RedirectToAction("Index", "Home", user)); } /* Login Failed */ else { ModelState.AddModelError("Password", "A password inserida não é valida"); } } else/*User not found. Please register*/ { ModelState.AddModelError("Username", "O username inserido não corresponde a nenhum utilizador registado."); } return(View(accountModel)); }
public JsonResult ExistingLists(int id) { var user = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name); return(user.CanReadBoard(id) ? Json( ListDataMapper.GetListDataMapper().GetAllByBoard(BoardDataMapper.GetBoardDataMapper().GetById(id)), JsonRequestBehavior.AllowGet) : null); }
public bool BoardExists(String id) { var user = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name); var board = BoardDataMapper.GetBoardDataMapper().GetBoardByUserAndName(user, id); return(board != null); }
public ActionResult SetImage(FormCollection fc) { var user = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name); user.ImageUrl = fc["ImageUrl"]; return(RedirectToAction("ShowInfo", user)); }
public ActionResult Register() { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home", AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name))); } return(View()); }
public ActionResult Index() { var bm = BoardDataMapper.GetBoardDataMapper(); var boards = bm.GetBoardsFrom(AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name)); return(View(boards)); }
public ActionResult LogOn() { FormsAuthentication.SignOut(); if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home", AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name))); } return(View()); }
public ActionResult Delete(string id) { if (User.IsInRole("Admin") || User.Identity.Name.Equals(id)) { var accs = AccountDataMapper.GetAccountDataMapper(); accs.Remove(accs.GetById(id)); return(RedirectToAction("ControlPanel", "Admin")); //ToDo } return(RedirectToAction("Index", "Home")); }
public ActionResult ToAdmin(string id) { var acc = AccountDataMapper.GetAccountDataMapper().GetById(id); if (!acc.Roles.Contains("Admin")) { acc.Roles.Add("Admin"); } return(RedirectToAction("ControlPanel")); }
public ActionResult CreateCard(CardsModel c, int id) { c.List = ListDataMapper.GetListDataMapper().GetById(id); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(c.List.Board.Id)) { return(RedirectToAction("Index", "Boards")); } CardDataMapper.GetCardDataMapper().Add(c); return(Redirect(String.Format("~/Lists/GetCards/{0}", id))); }
public override string[] GetRolesForUser(string username) { var acc = AccountDataMapper.GetAccountDataMapper().GetById(username); if (acc == null) { return new string[] {} } ; return(acc.Roles.ToArray()); }
public ActionResult Edit(ListsModel listsModel) { var list = ListDataMapper.GetListDataMapper().GetById(listsModel.Id); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(list.Board.Id)) { return(RedirectToAction("Index", "Boards")); } list.Name = listsModel.Name; return(RedirectToAction("GetLists", "Boards", new { id = list.Board.Id })); }
public ActionResult RemoveList(ListsModel listsModel) { var list = ListDataMapper.GetListDataMapper().GetById(listsModel.Id); int boardId = list.Board.Id; if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(boardId)) { return(RedirectToAction("Index", "Boards")); } ListDataMapper.GetListDataMapper().Remove(list); return(RedirectToAction("GetLists", "Boards", new { id = boardId })); }
public ActionResult Edit(int id) { var card = CardDataMapper.GetCardDataMapper().GetById(id); if (card == null) { return(RedirectToAction("Http404", "Errors")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(card.List.Board.Id)) { return(RedirectToAction("Index", "Boards")); } return(View(card)); }
public ActionResult Create(BoardsModel boardsModel) { var bm = BoardDataMapper.GetBoardDataMapper(); if (bm.GetByName(boardsModel.Name) == null) { bm.Add(boardsModel); var acc = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name); acc.AddBoard(boardsModel); return(RedirectToAction("Index")); } ModelState.AddModelError("Name", "Já existe um Quadro com esse nome"); return(View(boardsModel)); }
public ActionResult CreateList(ListsModel listsModel, int id) { var board = BoardDataMapper.GetBoardDataMapper().GetById(id); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id)) { return(RedirectToAction("Index")); } listsModel.Board = board; var ldm = ListDataMapper.GetListDataMapper(); ldm.Add(listsModel); return(Redirect(String.Format("~/Boards/GetLists/{0}", id))); }
public ActionResult Archive(CardsModel cardsModel) { var card = CardDataMapper.GetCardDataMapper().GetById(cardsModel.Id); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(card.List.Board.Id)) { return(RedirectToAction("Index", "Boards")); } var listId = card.List.Id; int cardIdx = card.Idx; RefreshIdx(CardDataMapper.GetCardDataMapper().GetAllByList(card.List), cardIdx); card.List = null; return(RedirectToAction("GetCards", "Lists", new { id = listId })); }
public ActionResult Edit(CardsModel cardsModel) { var card = CardDataMapper.GetCardDataMapper().GetById(cardsModel.Id); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(card.List.Board.Id)) { return(RedirectToAction("Index", "Boards")); } card.Name = cardsModel.Name; if (card.List != null) { return(RedirectToAction("GetCards", "Lists", new { id = card.List.Id })); } return(RedirectToAction("GetCard", new { card.Id })); }
public ActionResult CreateCard(int id) { var list = ListDataMapper.GetListDataMapper().GetById(id); if (list == null) { return(Redirect("~/Errors/Http404")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(list.Board.Id)) { return(RedirectToAction("Index", "Boards")); } return(View(new CardsModel { List = list })); }
public ActionResult Edit(BoardsModel boardsModel) { var board = BoardDataMapper.GetBoardDataMapper().GetById(boardsModel.Id); if (board == null) { return(RedirectToAction("Http404", "Errors")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id)) { return(RedirectToAction("Index")); } board.Name = boardsModel.Name; board.Description = boardsModel.Description; return(RedirectToAction("Index")); }
public ActionResult RemoveWriteRights(int id) { var board = BoardDataMapper.GetBoardDataMapper().GetById(id); if (board == null) { return(RedirectToAction("Http404", "Errors")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id)) { return(RedirectToAction("Index")); } return(View(new RightsModel { BoardId = id })); }
public ActionResult GetCardsByAjaxRequest(int id) { var list = ListDataMapper.GetListDataMapper().GetById(id); if (list == null) { return(RedirectToAction("Http404", "Errors")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanReadBoard(list.Board.Id)) { return(RedirectToAction("Index", "Boards")); } var cm = CardDataMapper.GetCardDataMapper().GetAllByList(list); return(PartialView(cm)); }
// // GET: /Home/ public ActionResult Search(String id) { int counter = 5; var result = new List <KeyValuePair <String, String> >(); BoardDataMapper b = BoardDataMapper.GetBoardDataMapper(); //Guarda os boards do user e procura boards cujo nome contenha id IEnumerable <BoardsModel> boards = b.GetBoardsFrom(AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name)); GetResultsByName(boards, "/Boards/GetLists/", "[Board]", result, counter, id); //No caso de ainda poderem ser adicionados resultados adiciona lists if (counter > 0) { //Procura listas var allLists = new List <ListsModel>(); ListDataMapper l = ListDataMapper.GetListDataMapper(); foreach (BoardsModel bm in boards) { IEnumerable <ListsModel> lists = l.GetAllByBoard(bm); allLists.AddRange(lists); GetResultsByName(lists, "/Lists/GetCards/", "[List]", result, counter, id); } //Se ainda poderem ser adicionados resultados adiciona cards if (counter > 0) { var allCards = new List <CardsModel>(); CardDataMapper c = CardDataMapper.GetCardDataMapper(); foreach (ListsModel lm in allLists) { IEnumerable <CardsModel> cards = c.GetAllByList(lm); allCards.AddRange(cards); GetResultsByName(cards, "/Cards/GetCard/", "[Card]", result, counter, id); } //Se ainda poderem ser adicionados resultados adiciona cards pela descrição if (counter > 0) { GetResultsByDescription(allCards, "/Cards/GetCard/", "[Card]", result, counter, id); } } } return(PartialView("Search", result)); }
public ActionResult RemoveList(int id) { var list = ListDataMapper.GetListDataMapper().GetById(id); if (list == null) { return(RedirectToAction("Http404", "Errors")); } if (CardDataMapper.GetCardDataMapper().GetAllByList(list).Count() != 0) { return(RedirectToAction("GetCards", new { id })); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(list.Board.Id)) { return(RedirectToAction("Index", "Boards")); } return(View(list)); }
public ActionResult ChangePassword(ChangePasswordModel changePasswordModel) { var user = User.Identity.Name; var adm = AccountDataMapper.GetAccountDataMapper(); var acc = adm.GetById(user); if (ModelState.IsValid) { if (!LoginUtils.ComparePasswords(changePasswordModel.OldPw, acc)) { ModelState.AddModelError("OldPw", "Password incorrecta!"); return(View(changePasswordModel)); } acc.Password = changePasswordModel.Pw1; LoginUtils.EncryptPassword(acc); return(View("PasswordChanged")); } return(View(changePasswordModel)); }
public ActionResult MoveCardInList(CardsModel cardsModel) { var card = CardDataMapper.GetCardDataMapper().GetById(cardsModel.Id); int oldIdx = card.Idx; int newIdx = cardsModel.Idx; IEnumerable <CardsModel> cardsEnum = CardDataMapper.GetCardDataMapper().GetAllByList(card.List); int nCards = cardsEnum.Count(); if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(card.List.Board.Id)) { return(RedirectToAction("Index", "Boards")); } if (nCards < newIdx) { newIdx = nCards; } if (oldIdx < newIdx) { foreach (var c in cardsEnum) { if (c.Idx > oldIdx && c.Idx <= newIdx) { --c.Idx; } } } else if (newIdx < oldIdx) { foreach (var c in cardsEnum) { if (c.Idx < oldIdx && c.Idx >= newIdx) { ++c.Idx; } } } card.Idx = newIdx; return(RedirectToAction("GetCards", "Lists", new { id = card.List.Id })); }
public ActionResult ChangeEmail(ChangeEmailModel changeEmailModel) { var user = User.Identity.Name; var adm = AccountDataMapper.GetAccountDataMapper(); var acc = adm.GetById(user); if (ModelState.IsValid) { if (!changeEmailModel.OldEmail.Equals(acc.Email)) { ModelState.AddModelError("OldEmail", "Esta conta não está associada a este email"); return(View(changeEmailModel)); } acc.Email = changeEmailModel.NewEmail; LoginUtils.AddToConfirmList(acc); FormsAuthentication.SignOut(); return(View("Confirmation")); } return(View(changeEmailModel)); }
public ActionResult GetCards(int id) { var list = ListDataMapper.GetListDataMapper().GetById(id); if (list == null) { return(RedirectToAction("Http404", "Errors")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanReadBoard(list.Board.Id)) { return(RedirectToAction("Index", "Boards")); } var cm = CardDataMapper.GetCardDataMapper().GetAllByList(list); if (cm.Count() != 0) { return(View(cm)); } return(View("Empty", list)); }
public ActionResult GetLists(int id) { var board = BoardDataMapper.GetBoardDataMapper().GetById(id); if (board == null) { return(Redirect("~/Errors/Http404")); } if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanReadBoard(board.Id)) { return(RedirectToAction("Index")); } var ie = ListDataMapper.GetListDataMapper().GetAllByBoard(board); if (ie.Count() != 0) { return(View(ie)); } return(View("Empty", board)); }
public static AccountModel RegisterAccount(RegisterAccountModel registerAccountModel) { var adm = AccountDataMapper.GetAccountDataMapper(); if (adm.GetById(registerAccountModel.Username.ToLower()) == null) { AccountModel accountModel = new AccountModel(); accountModel.Username = registerAccountModel.Username.ToLower(); accountModel.Password = registerAccountModel.Password; accountModel.Email = registerAccountModel.Email; EncryptPassword(accountModel); accountModel.Roles = new List <string>() { "User" }; adm.Add(accountModel); AddToConfirmList(accountModel); return(accountModel); } return(null); }