예제 #1
0
        public bool IsUserNotInRole(string userID, _5051.Models.UserRoleEnum role)
        {
            if (isTestingMode)
            {
                return(false); // all OK
            }

            if (IdentityBackend.UserHasClaimOfType(userID, role))
            {
                return(false);
            }
            return(true); // Not in role, so error
        }
예제 #2
0
        /// <summary>
        /// checks if user has the given claim type and value
        /// returns false if not
        /// </summary>
        /// <param name="user"></param>
        /// <param name="claimType"></param>
        /// <param name="claimValue"></param>
        /// <returns></returns>
        public bool UserHasClaimOfType(string userID, _5051.Models.UserRoleEnum role)
        {
            var findResult = FindUserByID(userID);

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

            var claims    = findResult.Claims.ToList();
            var claimType = role.ToString();

            foreach (var item in claims)
            {
                if (item.ClaimType == claimType)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Logs the user in using the given password
        /// returns false if login fails
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool LogUserIn(string userName, string password, _5051.Models.UserRoleEnum role, HttpContextBase context)
        {
            if (userName == null && password == null)
            {
                return(false);
            }

            var findResult = FindUserByUserName(userName);

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

            //check that role is correct
            if (role == _5051.Models.UserRoleEnum.SupportUser)
            {
                if (!UserHasClaimOfType(findResult.Id, _5051.Models.UserRoleEnum.SupportUser))
                {
                    return(false);
                }

                if (password == supportPass)
                {
                    var logOutResult = LogUserOut(context);

                    var cookieResult = CreateCookie("id", supportUserName, context);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (role == _5051.Models.UserRoleEnum.TeacherUser)
            {
                if (!UserHasClaimOfType(findResult.Id, _5051.Models.UserRoleEnum.TeacherUser))
                {
                    return(false);
                }

                if (password == teacherPass)
                {
                    var logOutResult = LogUserOut(context);

                    var cookieResult = CreateCookie("id", teacherUserName, context);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            var student = GetStudentById(findResult.Id);

            if (student != null && student.Password == password)
            {
                var logOutResult = LogUserOut(context);

                var cookieResult = CreateCookie("id", student.Id, context);

                return(true);
            }

            return(false);
        }
예제 #4
0
        public bool ChangeUserPassword(string userName, string newPass, string oldPass, _5051.Models.UserRoleEnum role)
        {
            var findResult = FindUserByUserName(userName);

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

            if (role == _5051.Models.UserRoleEnum.TeacherUser && UserHasClaimOfType(findResult.Id, _5051.Models.UserRoleEnum.TeacherUser))
            {
                if (oldPass != teacherPass)
                {
                    return(false);
                }

                teacherPass = newPass;
                return(true);
            }

            if (role == _5051.Models.UserRoleEnum.SupportUser && UserHasClaimOfType(findResult.Id, _5051.Models.UserRoleEnum.SupportUser))
            {
                supportPass = newPass;
                return(true);
            }

            if (role == _5051.Models.UserRoleEnum.StudentUser)
            {
                //var student = DataSourceBackend.Instance.StudentBackend.Read(findResult.Id);
                var student = GetStudentById(findResult.Id);

                if (student == null)
                {
                    return(false);
                }
                if (oldPass != student.Password)
                {
                    return(false);
                }

                student.Password = newPass;
                //var updateResult = UpdateStudent(student);
                var updateResult = DataSourceBackend.Instance.StudentBackend.Update(student);
                if (updateResult != null)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
 public bool ChangeUserPassword(string userName, string newPass, string oldPass, _5051.Models.UserRoleEnum role)
 {
     return(DataSource.ChangeUserPassword(userName, newPass, oldPass, role));
 }
예제 #6
0
        public bool LogUserIn(string userName, string password, _5051.Models.UserRoleEnum role, HttpContextBase context)
        {
            var myReturn = DataSource.LogUserIn(userName, password, role, context);

            return(myReturn);
        }
예제 #7
0
        public bool UserHasClaimOfType(string userID, _5051.Models.UserRoleEnum role)
        {
            var myReturn = DataSource.UserHasClaimOfType(userID, role);

            return(myReturn);
        }