public function Create() { $this->LogInfo("company create ..."); $obj = $this->GetCommonData(); //创建公司 $companyDao = $this->GetModel(); $condition['company_name'] = $obj->company_name; $companyID = $companyDao->where($condition)->getField('company_id'); if ($companyID != '') { $this->LogWarn("Create company failed, company has exist. Company_name is " . $obj->company_name); $this->errorCode = MispErrorCode::COMPANY_EXISTED; $this->ReturnJson(); return; } $object = $this->objectToArray($obj); $object['company_status'] = CompanyEnum::STATUS_NORMAL; try { $companyID = MispCommonService::Create($companyDao, $object); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } //创建公司基本角色 try { $roleID = $this->CreateBasicRole($companyID); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } //创建System user $systemUserDao = MispDaoContext::SystemUser(); $user['user_name'] = $obj->user_name; $user['password'] = "******"; $user['role_id'] = $roleID; //增加公司时,同时增加了一个企业管理员账户 $user['reg_date'] = date('Y-m-d H:i:s', time()); $user['company_id'] = $companyID; $this->LogInfo("Create first admin of company, user info is " . json_encode($user)); try { $userID = MispCommonUserService::Create($user); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } //创建admin $admin['user_id'] = $userID; $admin['user_name'] = $obj->user_name; $admin['company_id'] = $companyID; $this->LogInfo("Create first admin of company, admin info is " . json_encode($admin)); $this->errorCode = MispServiceContext::UserManage()->CreateAdmin($admin); $this->ReturnJson(); }
public function Create() { $this->LogInfo("create user..."); $systemUserDao = MispDaoContext::SystemUser(); $req = $this->GetCommonData(); $user['user_name'] = $req->user_name; $user['password'] = $req->password; $user['role_id'] = $req->role_id; $user['reg_date'] = date('Y-m-d H:i:s', time()); $user['company_id'] = CompanyEnum::GROUP_COMPANY; try { $result = MispCommonUserService::Create($user); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } $this->ReturnJson(); }
public function Delete() { $Req = $this->GetReqObj(); $this->LogInfo("customer delete, customer_id is " . $Req->obj); //删除会员信息 $customerDao = $this->GetModel(); $customerCondition[$customerDao->getPk()] = $Req->obj; try { $result = MispCommonService::Delete($customerDao, $customerCondition); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } //删除用户信息 $this->errorCode = MispCommonUserService::Delete($Req->obj); $this->ReturnJson(); }
public function Delete() { $Req = $this->GetReqObj(); $this->LogInfo("admin delete, user_id is " . $Req->obj); if ($Req->obj == $_SESSION['user']['user_id']) { $this->LogWarn("Delete admin failed, can not delete yourself."); $this->errorCode = MispErrorCode::CANT_DELETE_YOURSELF; $this->ReturnJson(); return; } //删除管理员信息 $adminDao = $this->GetModel(); $adminCondition[$adminDao->getPk()] = $Req->obj; try { $result = MispCommonService::Delete($adminDao, $adminCondition); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); $this->ReturnJson(); return; } //删除用户信息 $this->errorCode = MispCommonUserService::Delete($Req->obj); $this->ReturnJson(); }
public function Login() { $Req = $this->GetReqObj(); $req = $this->GetCommonData(); $reqType = $this->GetReqType(); $this->LogInfo("User login, Client type is " . $reqType); $user['user_name'] = $req->user_name; $user['password'] = $req->password; if ($reqType == ClientTypeEnum::IOS || $reqType == ClientTypeEnum::ANDROID) { //APP客户端登陆验证 $data = null; $user['company_id'] = $Req->app_id; $this->LogInfo("Login client type is " . $reqType . ",company_id is " . $Req->app_id); //验证用户与登录密码 try { $orignalUser = MispCommonUserService::LoginValidate($user); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); return $this->ReturnJson(); } //获取用户APP登录权限 $privilegeResult = MispCommonDataService::GetRolePrivilege($orignalUser, PrivilegeEnum::ACCESS_TYPE_LOGIN, PrivilegeEnum::ACCESS_VALUE_APP_LOGIN); if (false == $privilegeResult) { //用户不存在APP登录权限 $this->LogWarn("Get role privilege failed.The user don't have APP login privilege, login failed."); $this->errorCode = MispErrorCode::USERNAME_OR_PASSWORD_WRONG; return $this->ReturnJson(); } else { //获取登录权限成功 $this->LogInfo("Get user login privilege success. The user have APP login privilege."); //判断是否已经在其他设备登录 $condition['user_id'] = $orignalUser['user_id']; $tokenDao = MispDaoContext::Token(); $tokenCount = $tokenDao->where($condition)->count(); $this->LogInfo("Token count is " . $tokenCount); if ($tokenCount > 0) { //用户已在其他设备登录,删除已有token $this->LogInfo("The user has login in other device, user name is " . $orignalUser['user_name']); try { $result = MispCommonService::Delete($tokenDao, $condition); $this->LogInfo("Delete orginal token success."); } catch (FuegoException $e) { $this->LogWarn("Delete orginal token failed."); $this->LogWarn("Customer APPLogin failed"); $this->errorCode = MispErrorCode::ERROR_LOGIN_FAILED; $this->ReturnJson(); return; } } //APP登录成功 $data = MispServiceContext::UserManage()->AppLogin($orignalUser); } $this->ReturnJson($data); } if ($reqType == ClientTypeEnum::WEB) { //WEB端登陆验证 //验证用户与登录密码 try { $orignalUser = MispCommonUserService::LoginValidate($user); } catch (FuegoException $e) { $this->errorCode = $e->getCode(); return $this->ReturnJson(); } $privilegeResult = MispCommonDataService::GetRolePrivilege($orignalUser, PrivilegeEnum::ACCESS_TYPE_LOGIN, PrivilegeEnum::ACCESS_VALUE_WEB_LOGIN); if (false == $privilegeResult) { //用户不存在WEB登录权限 $this->LogWarn("Get role privilege failed. The user don't have WEB login privilege, login failed."); $this->errorCode = MispErrorCode::USERNAME_OR_PASSWORD_WRONG; } else { //WEB登录成功 $this->LogInfo("Get user login privilege success. The user have WEB login privilege."); $this->errorCode = MispServiceContext::UserManage()->WebLogin($orignalUser); } } $this->ReturnJson(); }