Пример #1
0
        //帳密驗證
        private UserClaims VerifyAccountPassword(string userName, string password, string serviceRole)
        {
            UserClaims userClaims = new UserClaims();

            userClaims.IsAuthenticated = false;
            userClaims.CompanyId       = 0;

            switch (serviceRole)
            {
            case APIServiceClient.SuperAdmin:
            {
                SuperAdminModel model = new SuperAdminModel();
                userClaims.IsAuthenticated = model.VerifyPassword(userName, password);
            }
            break;

            case APIServiceClient.Admin:
            {
                EmployeeModel model     = new EmployeeModel();
                int           companyId = model.VerifyPassword(userName, password);

                if (companyId != -1)
                {
                    userClaims.IsAuthenticated = true;
                    userClaims.CompanyId       = companyId;
                }
            }
            break;

            case APIServiceClient.Device:
                AccountModels accountModels = new AccountModels();
                userClaims.IsAuthenticated = accountModels.CheckIoTDevicePassword(userName, password);
                break;

            case APIServiceClient.External:
            {
                CompanyModel model     = new CompanyModel();
                int          companyId = model.GetIdByExtAppAuthenticationKey(password);

                if (companyId != -1)
                {
                    userClaims.IsAuthenticated = true;
                    userClaims.CompanyId       = companyId;
                }
            }
            break;
            }
            return(userClaims);
        }