コード例 #1
0
ファイル: TokenManagerBase.cs プロジェクト: dunglh/MyProject
 internal DungLH.Util.Token.Core.UserData GetValidUserData(string loginname, string password, string applicationCode, CommonParam commonParam)
 {
     DungLH.Util.Token.Core.UserData result = null;
     try
     {
         AasLoginSDO loginSDO = new AasLoginSDO();
         loginSDO.ApplicationCode = applicationCode;
         loginSDO.Loginname       = loginname;
         loginSDO.Password        = password;
         User user = null;
         if (!new TokenLoginProcessor(commonParam).Run(loginSDO, ref user))
         {
             LogSystem.Warn("Khong tim thay du lieu User dang nhap");
         }
         else
         {
             result = new DungLH.Util.Token.Core.UserData();
             result.ApplicationCode = applicationCode;
             result.Email           = user.Email;
             result.Loginname       = user.Loginname;
             result.Mobile          = user.Mobile;
             result.Username        = user.Username;
         }
     }
     catch (Exception ex)
     {
         DungLH.Util.CommonLogging.LogSystem.Error(ex);
         result = null;
     }
     return(result);
 }
コード例 #2
0
ファイル: TokenLoginCheck.cs プロジェクト: dunglh/MyProject
        internal bool VerifyRequireField(AasLoginSDO data)
        {
            bool valid = true;

            try
            {
                if (data == null)
                {
                    throw new ArgumentNullException("data");
                }
                if (String.IsNullOrWhiteSpace(data.ApplicationCode))
                {
                    throw new ArgumentNullException("data.ApplicationCode");
                }
                if (String.IsNullOrWhiteSpace(data.Loginname))
                {
                    throw new ArgumentNullException("data.Loginname");
                }
                if (String.IsNullOrWhiteSpace(data.Password))
                {
                    throw new ArgumentNullException("data.Password");
                }
                data.Loginname = data.Loginname.ToLower().Trim();
            }
            catch (ArgumentNullException ex)
            {
                BugUtil.SetBugCode(param, LibraryBug.Bug.Enum.Common__ThieuThongTinBatBuoc);
                LogSystem.Error(ex);
                valid = false;
            }
            catch (Exception ex)
            {
                LogSystem.Error(ex);
                valid = false;
                param.HasException = true;
            }
            return(valid);
        }
コード例 #3
0
        internal bool Run(AasLoginSDO data, ref User resultData)
        {
            bool result = false;

            try
            {
                bool            valid       = true;
                User            raw         = null;
                Application     application = null;
                TokenLoginCheck checker     = new TokenLoginCheck(param);
                AasUserCheck    userChecker = new AasUserCheck(param);
                valid = valid && checker.VerifyRequireField(data);
                valid = valid && userChecker.VerifyLoginname(data.Loginname, ref raw);
                valid = valid && userChecker.IsUnLock(raw);
                if (valid)
                {
                    if (!new DungLH.Util.Token.Password.PasswordManager().CheckPassword(raw.Password, data.Password, raw.Salt, data.Loginname))
                    {
                        MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanHoacMatKhauKhongChinhXac);
                        throw new Exception("Tai khoa hoac mat khau khong chinh xac");
                    }

                    application = new ApplicationManagerGet().GetByCode(data.ApplicationCode);
                    if (application == null)
                    {
                        MessageUtil.SetMessage(param,
                                               LibraryMessage.Message.Enum.Common_UngDungChuaDuocDangKyTrenHeThong);
                        throw new Exception("ApplicationCode invalid: " + data.ApplicationCode);
                    }

                    List <ApplicationRole> appRoles = new ApplicationRoleManagerGet().GetByApplicationId(application.Id);
                    if (!IsNotNullOrEmpty(appRoles))
                    {
                        MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung);
                        throw new Exception("Ung dung cua duc gan vao vao tro nao");
                    }

                    List <UserRole> userRoles = new UserRoleManagerGet().GetByUserId(raw.Id);
                    if (!IsNotNullOrEmpty(userRoles))
                    {
                        MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung);
                        throw new Exception("Nguoi dung chua duc gan vai trong o cho naof");
                    }

                    List <long> userRoleIds = userRoles.Select(s => s.RoleId).ToList();
                    if (!appRoles.Exists(e => userRoleIds.Contains(e.RoleId)))
                    {
                        MessageUtil.SetMessage(param, LibraryMessage.Message.Enum.Common_TaiKhoanKhongCoQuyenTruyCapUngDung);
                        throw new Exception("Nguoi dung khong duoc phan quyen truy cap vao ung dung");
                    }
                    raw.Password = "";
                    resultData   = raw;
                    result       = true;
                }
            }
            catch (Exception ex)
            {
                DungLH.Util.CommonLogging.LogSystem.Error(ex);
                result = false;
            }
            return(result);
        }