コード例 #1
0
ファイル: DbUtility.cs プロジェクト: sifayideenjs/SXaYmZple
        public static List <string> GetFormList(UserManagementDb dbContext)
        {
            string errorMessage;
            var    formdataset = dbContext.LoadComboDetails("FORM", out errorMessage);
            var    formDetails = GetFormDetails(formdataset);

            return(formDetails.Select(f => f.FormName).ToList());
        }
コード例 #2
0
        public GroupViewModel(UserManagementDb userManagementDb)
        {
            this.userManagementDb = userManagementDb;

            string errorMessage;
            var    formdataset = userManagementDb.LoadComboDetails("FORM", out errorMessage);
            var    formDetails = GetFormDetails(formdataset);

            this.Forms = new List <GroupFormViewModel>(formDetails.Select(fd => new GroupFormViewModel(fd.FormID, fd.CustomeText, this)));

            this.SaveCommand = new RelayCommand(this.ExecuteSaveCommand, this.CanExecuteSaveCommand);
        }
コード例 #3
0
        private void InitializeGroups()
        {
            string errorMessage = string.Empty;

            var formdataset = userManagementDb.LoadComboDetails("FORM", out errorMessage);
            var formDetails = GetFormDetails(formdataset);

            var groupdataset = this.userManagementDb.LoadComboDetails("GROUP", out errorMessage);
            var groupDetails = GetGroupDetails(groupdataset);

            this.Groups = new ObservableCollection <GroupViewModel>(groupDetails.Select(gd => new GroupViewModel(userManagementDb, gd, formDetails)));
        }
コード例 #4
0
        private void InitializeUsers()
        {
            string errorMessage = string.Empty;

            var groupdataset = this.userManagementDb.LoadComboDetails("GROUP", out errorMessage);

            groupDetails = GetGroupDetails(groupdataset);

            var userdataset = userManagementDb.LoadComboDetails("USER", out errorMessage);
            var userDetails = GetUserDetails(userdataset);

            this.Users = new ObservableCollection <UserViewModel>(userDetails.Select(ud => new UserViewModel(userManagementDb, groupDetails, ud)));
        }
コード例 #5
0
        //private class InternalUserData
        //{
        //    public InternalUserData(string name, string username, string hashedPassword, string role)
        //    {
        //        Name = name;
        //        Username = username;
        //        HashedPassword = hashedPassword;
        //        Role = role;
        //    }

        //    public string Name
        //    {
        //        get;
        //        private set;
        //    }

        //    public string Username
        //    {
        //        get;
        //        private set;
        //    }

        //    public string HashedPassword
        //    {
        //        get;
        //        private set;
        //    }

        //    public string Role
        //    {
        //        get;
        //        private set;
        //    }
        //}

        //private static readonly List<InternalUserData> _users = new List<InternalUserData>()
        //{
        //    new InternalUserData("Administrator", "Admin", "XYe3Vs7WzqV+aglmNmwxZg0XhDN0560nL6c0imwiUbU=", "Administrator"),
        //    new InternalUserData("Mark Zuckerberg", "Mark", "3t+xSzmHldJCtbneg/o3ISj4ISxYANB5iLJqHLKOgoY=", "User"),
        //    new InternalUserData("Satya Nadella", "Satya", "1TwZVFwIbBPmx7tG+O7xxDrJTdWCvrA0B45zDPkmito=", "User"),
        //    new InternalUserData("Sundar Pichai", "Pichai", "+JmEE5Mbfcxj5n45JiyVIZX3hsp/3BU/M847cBuoXUY=", "User")
        //};

        public User AuthenticateUser(string username, string clearTextPassword)
        {
            if (dbContext != null)
            {
                //InternalUserData userData = _users.FirstOrDefault(u => u.Username.Equals(username) && u.HashedPassword.Equals(CalculateHash(clearTextPassword, u.Username)));
                //if (userData == null)
                //{
                //    throw new UnauthorizedAccessException("Access denied. Please provide some valid credentials.");
                //}

                //return new User(userData.Username, userData.Username, userData.Role);

                string errorMessage       = string.Empty;
                var    userValidateDetail = dbContext.ValidateUser(username, clearTextPassword, out errorMessage);
                if (userValidateDetail != null && userValidateDetail.Code != -1 && userValidateDetail.UserId != -1 && userValidateDetail.GroupId != -1)
                {
                    //var userdataset = dbContext.LoadComboDetails("USER", out errorMessage);
                    //var userGroupDetails = GetUserDetails(userdataset);
                    //var userGroupDetail = userGroupDetails.Single(ud => ud.UserName.ToUpper() == username.ToUpper());
                    //var groupdataset = dbContext.GetGroupDetails(userGroupDetail.GroupID, out errorMessage);
                    //var groupDetail = GetGroupDetail(groupdataset);
                    //var groupFormRights = GetGroupFormRights(groupdataset);
                    //var formIds = groupFormRights.Select(gfr => gfr.FormID);
                    //var formdataset = dbContext.LoadComboDetails("FORM", out errorMessage);
                    //var formDetails = GetFormDetails(formdataset);
                    //var formNames = formDetails.Where(f => formIds.Any(fi => fi == f.FormID)).Select(f => f.FormName);

                    var groupdataset    = dbContext.GetGroupDetails(userValidateDetail.GroupId, out errorMessage);
                    var groupDetail     = GetGroupDetail(groupdataset);
                    var groupFormRights = GetGroupFormRights(groupdataset);
                    var formIds         = groupFormRights.Select(gfr => gfr.FormID);
                    var formdataset     = dbContext.LoadComboDetails("FORM", out errorMessage);
                    var formDetails     = GetFormDetails(formdataset);
                    var formNames       = formDetails.Where(f => formIds.Any(fi => fi == f.FormID)).Select(f => f.FormName);

                    return(new User(userValidateDetail.UserId, userValidateDetail.Name, username, groupDetail.GroupName, formNames.ToArray()));
                }
                else
                {
                    throw new UnauthorizedAccessException("Access denied. Please provide some valid credentials.");
                }
            }
            else
            {
                throw new UnauthorizedAccessException("Access denied. Please contact your administrator.");
            }
        }
コード例 #6
0
        public async Task <IHttpActionResult> LoadComboDetails(string flag)
        {
            try
            {
                DataSet details = await Task.Run(() => usermanagementDb.LoadComboDetails(flag));

                if (details == null)
                {
                    return(NotFound());
                }

                return(Ok(details));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }