Esempio n. 1
0
        public AccessViewModel AccessViewModel(RegisterV2ViewModel registerViewModel)
        {
            var accessViewModel = new AccessViewModel();

            accessViewModel.Edit = EditRegister(registerViewModel);
            accessViewModel.Add  = AddToRegister(registerViewModel);
            accessViewModel.EditListOfRegisterItems = EditRegisterItemsList(registerViewModel);
            accessViewModel.Delete = DeleteRegister(registerViewModel);
            return(accessViewModel);
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "Id,RoleId,PermissionId,IsGranted,IsDeleted,ModifiedDate,ModifiedUserId,DeletionDate,DeletionUserId,CreatedDate,CreatedUserId")] AccessViewModel accessViewModel)
 {
     if (ModelState.IsValid)
     {
         accessViewModel.UpdateAccess();
         return(RedirectToAction("Index"));
     }
     UpdateList();
     ViewBag.PermissionId = new SelectList(listPermission, "Id", "Name", accessViewModel.PermissionId);
     ViewBag.RoleId       = new SelectList(listRole, "Id", "Name", accessViewModel.RoleId);
     return(View(accessViewModel));
 }
        public ActionResult ChangeDocAccess(int docId, DocumentAccess oldIdAccess)
        {
            var model = new AccessViewModel()
            {
                DocumentID = docId,
                OldAccess  = oldIdAccess,
                NewAccess  = oldIdAccess,
                ListAccess = accessRepository.GetAccess()
            };

            return(PartialView(model));
        }
Esempio n. 4
0
        public ActionResult AddGroup(AccessViewModel AVM)
        {
            checkLogin();

            int newID = AVM.newGroup.ID = GS.getNewID();

            AVM.group.Add(AVM.newGroup);
            AVM.newGroup = new USER_GROUP();

            ModelState.Clear();
            TempData["showForm"] = true;
            return(_Accesses(AVM, newID));
        }
Esempio n. 5
0
        //Show popup confirm delete
        public ActionResult DeleteAccess(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AccessViewModel record = new AccessViewModel();

            record.AccessId = id;

            return(PartialView("_DeleteAccessInfo", record));
        }
        public ActionResult ListAccessHistory(DateTime?startDate, DateTime?endDate, Guid userId,
                                              AccessType accessType = AccessType.All, int page = 1)
        {
            var range = new DateRange
            {
                StartDate = startDate,
                EndDate   = endDate
            };

            var historyService = new HistoryService(_context, new DefaultDateTimeHumanizeStrategy());

            return(Json(AccessViewModel.FromEntityList(historyService.SearchAccess(range, page, userId, accessType)),
                        JsonRequestBehavior.AllowGet));
        }
Esempio n. 7
0
        public ActionResult RemoveGroup(AccessViewModel AVM, int group_id)
        {
            checkLogin();

            AVM.group.Remove(AVM.group.Where(g => g.ID == group_id).FirstOrDefault());

            if (group_id > 0)
            {
                AVM.inactiveList.Add(group_id);
            }

            ModelState.Clear();
            TempData["showForm"] = true;
            return(View("Accesses", AVM));
        }
Esempio n. 8
0
        public Reply Formulario([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            try {
                //Hacer la peticion aca
                using (mvcApiEntities1 db = new mvcApiEntities1()) {
                }
            }
            catch (Exception ex)
            {
                oR.result  = 1;
                oR.message = "Ocurrio un error " + ex;
            }
            return(null);
        }
Esempio n. 9
0
        public ReplyViewModel Login([FromBody] AccessViewModel DataAccess)
        {
            ReplyViewModel Resp = new ReplyViewModel();

            try
            {
                Resp = _service.login(DataAccess);
            }
            catch (Exception ex)
            {
                Resp.result  = 0;
                Resp.message = "Ocurrio Un Error";
            }

            return(Resp);
        }
Esempio n. 10
0
        public ActionResult AccessHistory()
        {
            const AccessType accessType = AccessType.File;

            ViewBag.AccessTypes = new SelectList(accessType.ToDataSource <AccessType>(), "Key", "Value");

            var range = new DateRange
            {
                StartDate = DateTime.Now.AddMonths(-1),
                EndDate   = DateTime.Now
            };

            var historyService = new HistoryService(_context, new DefaultDateTimeHumanizeStrategy());

            return(View(
                       AccessViewModel.FromEntityList(historyService.SearchAccess(range, 1, _loggedUser.Id, AccessType.All))));
        }
Esempio n. 11
0
        public ActionResult Accesses()
        {
            checkLogin();

            AccessViewModel AVM = new AccessViewModel()
            {
                group         = DBS.findALLRecords <USER_GROUP>(),
                inactiveList  = new List <int>(),
                newGroup      = new USER_GROUP(),
                groupRights   = new List <USER_GROUP_RIGHT>(),
                groupUserlist = new List <GroupUserView>()
            };


            ModelState.Clear();
            return(View(AVM));
        }
Esempio n. 12
0
        public ActionResult Create(AccessViewModel model)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                var strError       = string.Empty;
                var accessIdentity = new IdentityAccess {
                    Id = model.AccessId, AccessName = model.AccessName, Description = model.AccessDesc
                };
                try
                {
                    var isDuplicated = _identityStore.CheckAccessDuplicate(accessIdentity);
                    if (isDuplicated)
                    {
                        this.AddNotification(string.Format("Could not create access due to the access [{0}] is existed", model.AccessName), NotificationType.ERROR);
                        return(RedirectToAction("Index"));
                    }

                    result = _identityStore.CreateAccess(accessIdentity);
                    if (result)
                    {
                        this.AddNotification("The access [" + model.AccessName + "] is created succesfully", NotificationType.SUCCESS);

                        //Write log
                        var activityText = "Create new access [Name: {0}]";
                        activityText = string.Format(activityText, model.AccessName);
                        WriteActivityLog(activityText, ActivityLogType.CreateAccess, model.AccessId, TargetObjectType.Access);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        this.AddNotification("Could not create access due to database exception occurred", NotificationType.ERROR);
                    }
                }
                catch (Exception ex)
                {
                    strError = string.Format("Could not CreateAccess because: {0}", ex.ToString());
                    logger.Error(strError);
                    this.AddNotification(strError, NotificationType.ERROR);
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public async Task <IActionResult> AddAccess([FromBody] AccessViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _accessService.AddNewToyAccess(model);

                return(Ok("Access was granted!"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 14
0
        public ActionResult Index(AccessViewModel model)
        {
            var strError = string.Empty;

            try
            {
                model.AllAccess = _identityStore.GetAllAccess();
            }
            catch (Exception ex)
            {
                strError = string.Format("Could not GetAllAccess because: {0}", ex.ToString());
                logger.Error(strError);
                this.AddNotification(strError, NotificationType.ERROR);
            }

            model.AllControllers = Constant.GetAllControllers(Server.MapPath("~/Controllers"));
            return(View(model));
        }
Esempio n. 15
0
        public async Task <ActionResult> ExternalLoginConfirmation(AccessViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                var user = new EventorUser()
                {
                    UserName = model.ExternalSignupModel.UserName, Name = model.ExternalSignupModel.Name, Surname = model.ExternalSignupModel.Surname, Email = model.ExternalSignupModel.UserName
                };

                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }

                IdentityResult result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                }

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Registred");
                    await SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View("Access", model));
        }
Esempio n. 16
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            oR.Result = 0;

            try
            {
                using (AnimalesContext db = new AnimalesContext())
                {
                    oR.Result = 1;
                    var list = db.Usuario.Where(u => u.Email == model.Email && u.Pass == model.Pass && u.IdEstado == 1);

                    if (list.Count() > 0)
                    {
                        oR.Data = Guid.NewGuid().ToString();

                        Usuario oUsuario = list.First();
                        oUsuario.Token           = (string)oR.Data;
                        oUsuario.FechaExpiracion = DateTime.Now.AddSeconds(240);

                        db.Entry(oUsuario).State = EntityState.Modified;
                        db.SaveChanges();

                        oR.Count   = 1;
                        oR.Message = "Se ha generado el token correctamente";
                    }

                    else
                    {
                        oR.Message = "Usuario no valido";
                    }
                }
            }
            catch (Exception ex)
            {
                oR.Message = "Login fallo. " + ex.Message;
            }

            return(oR);
        }
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            oR.Result = 0;

            try
            {
                var listUsuario = db.Usuario.Where(u => u.Email == model.Email && u.Pass == model.Pass && u.IdEstado == 1);

                if (listUsuario.Count() > 0)
                {
                    var stringToken = Guid.NewGuid().ToString();
                    HttpContext.Response.Headers.Add("token", stringToken);

                    Usuario oUsuario = listUsuario.First();
                    oUsuario.Token = stringToken;
                    // TIEMPO PARA QUE CADUQUE EL TOKEN = 12 horas
                    oUsuario.FechaExpiracion = DateTime.Now.AddHours(12);

                    db.Entry(oUsuario).State = EntityState.Modified;
                    db.SaveChanges();

                    oR.Count   = 1;
                    oR.Message = "Se ha generado el token correctamente";
                    oR.Result  = 1;
                }

                else
                {
                    oR.Message = "Usuario no valido";
                    oR.Result  = 2;
                }
            }
            catch (Exception ex)
            {
                oR.Message = "Login fallo. " + ex.Message;
            }

            return(oR);
        }
Esempio n. 18
0
 // GET: Accesses/Details/5
 public ActionResult Details(Guid?id)
 {
     if (AccountController.CheckPermission("Access-Detail"))
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         UpdateList();
         AccessViewModel accessViewModel = listAccess.Find(x => x.Id == id);//db.AccessViewModels.Find(id);
         if (accessViewModel == null)
         {
             return(HttpNotFound());
         }
         return(View(accessViewModel));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 19
0
        public async Task <ActionResult> Login(AccessViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.LoginModel.UserName, model.LoginModel.Password);

                if (user != null)
                {
                    await SignInAsync(user, model.LoginModel.RememberMe);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View("Access", model));
        }
Esempio n. 20
0
        public async Task AddNewToyAccess(AccessViewModel model)
        {
            try
            {
                var alreadyOwned =
                    await _context.Accesses.AnyAsync(x => x.ToyId == model.ToyId &&
                                                     x.IsOwner &&
                                                     model.IsOwner);

                if (alreadyOwned)
                {
                    throw new Exception("This toy is already owned by someone");
                }

                var alreadyGrantedAccess =
                    await _context.Accesses.AnyAsync(x => x.ToyId == model.ToyId &&
                                                     x.UserId == model.UserId);

                if (alreadyGrantedAccess)
                {
                    throw new Exception("Access to this toy is already granted to this user");
                }

                var isToyIdInvalid = await _context.Toys.FirstOrDefaultAsync(x => x.Id == model.ToyId) == null;

                if (isToyIdInvalid)
                {
                    throw new Exception("This toy does not exist. Check your id or contact us");
                }

                await _context.Accesses.AddAsync(_mapper.Map <Access>(model));

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 21
0
        public Reply Login([FromBody] AccessViewModel model) // Se va a recibir como parametro el AccessViewModel
        {
            Reply oReply = new Reply();

            oReply.result = 0;
            try
            {
                using (Cursomvc_apiEntities db = new Cursomvc_apiEntities())
                {
                    var lst = from d in db.user
                              where d.email == model.email && d.password == model.password && d.idEstatus == 1
                              select d;

                    if (lst.Count() > 0)
                    {
                        oReply.result  = 1;
                        oReply.message = "Token asignado: ";
                        // Creo token
                        oReply.data = Guid.NewGuid().ToString(); // Genera identificador único, para ser implementado como token

                        // Para guardar token en la db
                        user oUser = lst.FirstOrDefault();
                        oUser.token = (string)oReply.data;
                        // Para editar valor en db
                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        oReply.message = "Datos incorrectos";
                    }
                }
            }
            catch (Exception ex)
            {
                oReply.message = "Hubo un error" + ex;
            }
            return(oReply);
        }
Esempio n. 22
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oReply = new Reply();

            oReply.result = 0;

            try
            {
                using (mvcApiEntities db = new mvcApiEntities())
                {
                    var oExistUser = from d in db.users
                                     where d.email == model.email && d.password == model.password && d.idStatus == 1
                                     select d;

                    if (oExistUser.FirstOrDefault() != null)
                    {
                        oReply.result = 1;
                        oReply.data   = Guid.NewGuid().ToString();

                        user oUser = oExistUser.First();
                        oUser.token = oReply.data.ToString();

                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        oReply.message = "Credenciales incorrectas";
                    }
                }
            }
            catch (Exception s)
            {
                oReply.message = "Error en la autenticacion" + s.Message;
            }

            return(oReply);
        }
Esempio n. 23
0
        public Reply Login(AccessViewModel model)
        {
            Reply Or = new Reply();

            Or.result = 0;

            try
            {
                //Contexto, Todo lo que esta creado aqui se destruye aqui (Es un ambito, universo)
                using (cursomvcapiEntities db = new cursomvcapiEntities())
                {
                    var lst = db.user.Where(d => d.email == model.email && d.password == model.password && d.idEstatus == 1);

                    if (lst.Count() > 0)
                    {
                        Or.result = 1;
                        //Crear y enviar el toque 32 caracteres no se repiten
                        Or.data = Guid.NewGuid().ToString();

                        user oUser = lst.First();
                        oUser.token           = (string)Or.data;
                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        Or.message = "Datos Incorrectos";
                    }
                }
            }
            catch (Exception ex)
            {
                Or.message = "Ocurrio un error, estamos corrigiendo";
            }

            return(Or);
        }
Esempio n. 24
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oReplay = new Reply();

            try
            {
                using (var dbContext = new Example002Entities())
                {
                    var query = from u in dbContext.Users
                                join s in dbContext.States on u.IdState equals s.Id
                                where s.Name.Equals("Active") && u.Email.Equals(model.email) && u.Password.Equals(model.password)
                                select u;

                    if (query.Count() == 1)
                    {
                        oReplay.result = 1;
                        oReplay.data   = Guid.NewGuid().ToString();

                        User oUser = query.First();
                        oUser.Token = oReplay.data.ToString();
                        dbContext.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        oReplay.message = "User's data are incorrect.";
                    }
                }
            }
            catch (Exception exception)
            {
                oReplay.message = string.Format("There was an error.", exception.Message);
            }

            return(oReplay);
        }
Esempio n. 25
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            oR.result = 0;
            try
            {
                using (PruebaEntities db = new PruebaEntities())
                {
                    var lst = db.Usuario.Where(d => d.username == model.username && d.password == model.password);

                    if (lst.Count() > 0)
                    {
                        oR.result = 1;
                        oR.data   = Guid.NewGuid().ToString();

                        Usuario oUser = lst.First();
                        oUser.token = (string)oR.data;

                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        oR.message = "Credenciales Erroneas";
                    }
                }
            }
            catch (Exception ex)
            {
                oR.result  = 0;
                oR.message = " Ocurrió un error!";
            }

            return(oR);
        }
Esempio n. 26
0
        public Reply Login([FromBody] AccessViewModel model)
        {
            Reply oR = new Reply();

            oR.result = 0;
            try
            {
                using (cursomvcapiEntities db = new cursomvcapiEntities())
                {
                    var lst = db.user.Where(d => d.email == model.email && d.password == model.password && d.idEstatus == 1);

                    if (lst.Count() > 0)
                    {
                        oR.result  = 1;
                        oR.data    = Guid.NewGuid().ToString();
                        oR.mensaje = "Exitoso";

                        user oUser = lst.First();
                        oUser.token = oR.data.ToString();

                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        oR.mensaje = "Datos incorrecto";
                    }
                }
            }
            catch (Exception ex)
            {
                oR.result  = 0;
                oR.mensaje = "Ha ocurrido un error";
            }
            return(oR);
        }
Esempio n. 27
0
 // GET: Accesses/Edit/5
 public ActionResult Edit(Guid?id)
 {
     if (AccountController.CheckPermission("Access-Edit"))
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         UpdateList();
         AccessViewModel accessViewModel = listAccess.Find(x => x.Id == id);//db.AccessViewModels.Find(id);
         if (accessViewModel == null)
         {
             return(HttpNotFound());
         }
         UpdateList();
         ViewBag.PermissionId = new SelectList(listPermission, "Id", "Name", accessViewModel.PermissionId);
         ViewBag.RoleId       = new SelectList(listRole, "Id", "Name", accessViewModel.RoleId);
         return(View(accessViewModel));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 28
0
 public ActionResult ManageAccess(AccessViewModel model)
 {
     model.AllAccess = _identityStore.GetAllAccess();
     return(View(model));
 }
Esempio n. 29
0
        public static async Task <bool> SetAuthorityAsync(Authentication authentication, IAccessibleDescriptor descriptor)
        {
            var dialog = await AccessViewModel.CreateInstanceAsync(authentication, descriptor);

            return(dialog?.ShowDialog() == true);
        }
Esempio n. 30
0
 public List <string> Delete(AccessViewModel obj)
 {
     throw new NotImplementedException();
 }