Esempio n. 1
0
        public Tuple<ClsReturnValues, string, List<ClsUserDisplay>> authenticateUser(string UserName, string Password, string DeviceType, string DeviceName, string Browser)
        {
            string encryptedPassword = Security.Encrypt(Password);
            string token = "";
            List<ClsUserDisplay> ud = new List<ClsUserDisplay>();
            ClsReturnValues result = new ClsReturnValues();
            ClsUsers userGroup = new ClsUsers();
            using (tdoEntities db = new tdoEntities())
            {
                result = db.uspUserAuthentication(UserName, encryptedPassword, DeviceType, DeviceName, Browser).FirstOrDefault();
                userGroup = db.uspGetUsers().Where(p => p.userID == result.ID).FirstOrDefault();

                if (result.IsSuccess == true)
                {

                    ud = db.uspGetUserDisplay(result.ID).ToList<ClsUserDisplay>();
                    // Token issuer
                    TokenIssuer issuer = new TokenIssuer();
                    // A client of the relying party app gets the token
                    token = issuer.GetToken(result, ud.First().userGroupID);

                }

            }
            return new Tuple<ClsReturnValues, string, List<ClsUserDisplay>>(result, token, ud);
        }
Esempio n. 2
0
        public static ClsReturnValues setUsers(ClsUsers obj)
        {
            //password encryption happens here
            obj.password = Security.Encrypt(obj.password);

            ClsReturnValues lst = new ClsReturnValues();
            using (var db = new tdoEntities())
            {

                lst = db.uspAddEditUsers(obj.userID, obj.userGroupID, obj.userName, obj.password, obj.password, obj.passwordCanExpire, obj.passwordExpiryDate, obj.isLocked, obj.loginAttempts, obj.lastLoginDate, obj.theme, obj.resetPassword, obj.createdByID, obj.sessionID).FirstOrDefault();
            }
            return lst;
        }
        public JsonResult setUsers(string userID, string userGroupID, string userName, string Password, int isLocked, int resetPassword)
        {
            List<ClsUserDisplay> userDisplay = new List<ClsUserDisplay>();
            using (tdoEntities db = new tdoEntities())
            {
                userDisplay = db.uspGetUserDisplay(GetID()).ToList<ClsUserDisplay>();
            }
            List<string> editableForms = Restriction.GetEditableForms(userDisplay);
            List<string> addableForms = Restriction.GetAddableForms(userDisplay);

            if (int.Parse(userID) == 0 && !addableForms.Contains("Users"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to add new records." });
            }
            else if (int.Parse(userID) != 0 && !editableForms.Contains("Users"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to edit records." });
            }

            Guid Session = new Guid(GetSession());
            if (Password == "") Password = "******";
            int _id = 0; try { _id = int.Parse(userID.Trim()); }
            catch { }
            int _grIid = 0; try { _grIid = int.Parse(userGroupID.Trim()); }
            catch { }
            bool Locked = false; bool reset = false;
            if (isLocked == 1) Locked = true; if (resetPassword == 1) reset = true;
            ClsUsers obj = new ClsUsers()
            {
                userID = _id,
                userGroupID = _grIid,
                userName = userName.Trim(),
                resetPassword = reset,
                password = Password,
                isLocked = Locked,
                createdByID = GetID(),
                theme = "Default",
                sessionID = Session
            };
            ClsReturnValues k = Administration.setUsers(obj);
            return Json(new { id = k.ID, isSuccess = k.IsSuccess ?? false ? 1 : 0, msg = k.Response });
        }