Beispiel #1
0
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(false);
            }
            var accountNumber = value.ToString();
            var context       = new VinculacionContext();

            return(Enumerable.Any(context.Users, u => accountNumber.Equals(u.AccountId)));
        }
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(false);
            }
            var email   = value.ToString();
            var context = new VinculacionContext();

            return(Enumerable.All(context.Users, u => !email.Equals(u.Email)));
        }
Beispiel #3
0
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(false);
            }
            var accountNumber = value.ToString();
            var context       = new VinculacionContext();
            var student       = context.Users.FirstOrDefault(x => x.AccountId == accountNumber);

            if (student != null)
            {
                return(student.Status == Status.Inactive);
            }
            return(false);
        }
Beispiel #4
0
 public PeriodRepository()
 {
     _db = new VinculacionContext();
 }
Beispiel #5
0
 public ProjectRepository()
 {
     _db = new VinculacionContext();
 }
Beispiel #6
0
 public StudentRepository()
 {
     _db = new VinculacionContext();
 }
 public FacultyRepository()
 {
     _context = new VinculacionContext();
 }
 public MajorRepository()
 {
     db = new VinculacionContext();
 }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            VinculacionContext context = new VinculacionContext();

            try
            {
                AuthenticationHeaderValue authValue = actionContext.Request.Headers.Authorization;
                if (authValue == null)
                {
                    CurrentUser = new CustomPrincipal("", new string[] { "Anonymous" });
                    if (!String.IsNullOrEmpty(Roles))
                    {
                        if (!CurrentUser.IsInRole(Roles))
                        {
                            actionContext.Response =
                                actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                            actionContext.Response.Headers.Add(BasicAuthResponseHeader,
                                                               BasicAuthResponseHeaderValue);
                            return;
                        }
                    }
                }
                if (authValue != null && !String.IsNullOrWhiteSpace(authValue.Parameter) &&
                    authValue.Scheme == BasicAuthResponseHeaderValue)
                {
                    Credentials parsedCredentials = ParseAuthorizationHeader(authValue.Parameter);
                    if (parsedCredentials != null)
                    {
                        var user = context.Users.FirstOrDefault(
                            u => u.Email == parsedCredentials.Username && u.Password == parsedCredentials.Password);
                        if (user != null)
                        {
                            var roles =
                                Enumerable.ToArray <string>(context.UserRoleRels.Where(u => u.User.Id == user.Id).Select(m => m.Role.Name));
                            var authorizedUsers = ConfigurationManager.AppSettings[UsersConfigKey];
                            var authorizedRoles = ConfigurationManager.AppSettings[RolesConfigKey];
                            Users       = String.IsNullOrEmpty(Users) ? authorizedUsers : Users;
                            Roles       = String.IsNullOrEmpty(Roles) ? authorizedRoles : Roles;
                            CurrentUser = new CustomPrincipal(parsedCredentials.Username, roles);
                            if (HttpContext.Current != null)
                            {
                                CurrentUser.UserId       = user.Id;
                                HttpContext.Current.User = CurrentUser;
                            }
                            if (!String.IsNullOrEmpty(Roles))
                            {
                                if (!CurrentUser.IsInRole(Roles))
                                {
                                    actionContext.Response =
                                        actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                                    actionContext.Response.Headers.Add(BasicAuthResponseHeader,
                                                                       BasicAuthResponseHeaderValue);
                                    return;
                                }
                            }
                            if (!String.IsNullOrEmpty(Users))
                            {
                                if (!Users.Contains(CurrentUser.UserId.ToString()))
                                {
                                    actionContext.Response =
                                        actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                                    actionContext.Response.Headers.Add(BasicAuthResponseHeader,
                                                                       BasicAuthResponseHeaderValue);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            throw new UnauthorizedAccessException("Usuario no valido");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, e.Message + ", Inner Exception: " + e.InnerException);
                }
                else
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, e.Message);
                }
                actionContext.Response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue);
                return;
            }
        }
Beispiel #10
0
 public HourRepository()
 {
     _db = new VinculacionContext();
 }
Beispiel #11
0
 public SectionRepository()
 {
     _db = new VinculacionContext();
 }
Beispiel #12
0
 public ClassRepository()
 {
     _db = new VinculacionContext();
 }
 public ProfessorRepository()
 {
     _db = new VinculacionContext();
 }