Beispiel #1
0
        public override bool ValidateUser(string email, string password)
        {
            var user = userService.GetByEmail(email);

            if (user != null && user.Password == password)
            {//TODO rewrite here
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public JsonResult GetFolders()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { redirect = "/account/login/" }, JsonRequestBehavior.AllowGet));
            }
            var user = userService.GetByEmail(User.Identity.Name);

            FolderModel[] folders = folderService.GetByAuthorId(user.Id).Select(folder => mapper.Map <FolderEntity, FolderModel>(folder)).ToArray();
            foreach (var folder in folders)
            {
                folder.ToDoLists = toDoListService.GetByFolderId(folder.Id).Select(toDoList => mapper.Map <ToDoListEntity, ToDoListModel>(toDoList)).ToArray();
            }
            return(Json(folders, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult GetItems(int toDoListId)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { redirect = "/account/login/" }, JsonRequestBehavior.AllowGet));
            }
            var            user            = userService.GetByEmail(User.Identity.Name);
            ToDoListEntity currentToDoList = toDoListService.GetById(toDoListId);
            //TODO check that user has permission to get items.
            var res = itemService.GetByToDoListId(toDoListId).Select(toDoList => mapper.Map <ItemEntity, ItemModel>(toDoList)).ToArray();

            return(Json(res,
                        JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
 public ActionResult Register(Register viewModel)
 {
     if (ModelState.IsValid)
     {
         var user = userService.GetByEmail(viewModel.Email);
         if (user != null)
         {
             ModelState.AddModelError("", "User with this address already registered.");
             return(View(viewModel));
         }
         var membershipUser = ((CustomMembershipProvider)Membership.Provider)
                              .CreateUser(viewModel.Email, viewModel.Password, viewModel.Name);
         if (membershipUser != null)
         {
             FormsAuthentication.SetAuthCookie(viewModel.Email, true);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("", "Error registration.");
         }
     }
     return(RedirectToAction("Index", "Home"));
 }
Beispiel #5
0
        public JsonResult GetByFolderId(int folderId)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { redirect = "/account/login/" }, JsonRequestBehavior.AllowGet));
            }
            var user = userService.GetByEmail(User.Identity.Name);

            if ((folderService.GetById(folderId)?.UserId ?? 0) != user.Id)
            {
                return(Json(new { redirect = "/account/login/" }, JsonRequestBehavior.AllowGet));
            }
            ToDoListModel[] lists = toDoListService.GetByFolderId(folderId).Select(list => mapper.Map <ToDoListEntity, ToDoListModel>(list)).ToArray();
            return(Json(lists, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public override bool IsUserInRole(string email, string roleName)
        {
            //var user = UserService.GetAll().FirstOrDefault(u => u.Login == email);
            var user = UserService.GetByEmail(email);

            if (user == null)
            {
                return(false);
            }

            var userRole = RoleService.GetById(user.RoleId);

            if (userRole != null && userRole.Name == roleName)
            {
                return(true);
            }

            return(false);

            //throw new NotImplementedException();
        }