public static function create($user) { $manager = new TransactionManager(); $transaction = $manager->get(); $user->setTransaction($transaction); if (true !== $user->create()) { $transaction->rollback("create user failed"); return false; } $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $user->email); $user = MaUser::findFirst($userId); if (empty($user)) { $transaction->rollback("cannot find user created"); return false; } $myspace = new MaTeam(); $myspace->setTransaction($transaction); $myspace->owner = $user->id; $myspace->name = 'MyMate'; $myspace->mission = 'Record My Growths'; $myspace->flag = MyConst::TEAM_FLAG_MYSPACE; if (true !== $myspace->create()) { $transaction->rollback("create myspace failed"); return false; } $mymate = new MaTeam(); $mymate->setTransaction($transaction); $mymate->owner = $user->id; $mymate->name = 'MyMate'; $mymate->mission = 'Follow and Share Growths With My Closest Friends'; $mymate->flag = MyConst::TEAM_FLAG_MYMATE; if (true !== $mymate->create()) { $transaction->rollback("create mymate failed"); return false; } $mentora = new MaTeam(); $mentora->setTransaction($transaction); $mentora->owner = $user->id; $mentora->name = 'Mentors'; $mentora->flag = MyConst::TEAM_FLAG_MENTOR; if (true !== $mentora->create()) { $transaction->rollback("create mentora failed"); return false; } $newbie = new MaTeam(); $newbie->setTransaction($transaction); $newbie->owner = $user->id; $newbie->name = 'Students'; $newbie->flag = MyConst::TEAM_FLAG_MENTOR; if (true !== $newbie->create()) { $transaction->rollback("create newbie failed"); return false; } $transaction->commit(); return true; }
private function getUserInfo($account) { $userId = null; if (MyTool::isEmail($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $account); } else { $userId = sprintf("%s='%s'", MyConst::FIELD_PHONE, $account); } return MaUser::findFirst($userId); }
/** * cgi/singup/verify/phone/{phone} */ public function checkPhoneAction($phone) { $phone = @trim($phone); if (!MyTool::isPhone($phone)) { return $this->onExit(MyConst::STATUS_INVALID_PHONE, 'wrong phone number: ' . $phone); } $userId = sprintf("%s='%s'", MyConst::FIELD_PHONE, $phone); $number = MaUser::count($userId); if ($number > 0) { return $this->onExit(MyConst::STATUS_PHONE_EXISTS, 'phone number already exists'); } return $this->onExit(MyConst::STATUS_OK); }
public static function getUser($account) { $userId = null; if (MyTool::isEmail($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_EMAIL, $account); } else { if (MyTool::isPhone($account)) { $userId = sprintf("%s='%s'", MyConst::FIELD_PHONE, $account); } else { $userId = sprintf("id=%s", $account); } } return MaUser::findFirst($userId); }
public function applyAction($targetId) { MyTool: simpleView(); if (!MyTool::loginAuth($this)) { return $this->onExit(MyConst::STATUS_NOT_LOGIN, 'must login first'); } $targetId = @intval($targetId); $uid = @intval(MyTool::getCookie($this, MyConst::COOKIE_UID)); // 是否已申请过 if (MaTeamInvitation::exists($uid, $targetId)) { return MyTool::onExit($this, MyConst::STATUS_EXISTS, 'record already exists'); } // 获取用户信息 $user = MaUser::getUser($uid); if (empty($user)) { return MyTool::onExit($this, MyConst::STATUS_ERROR, 'invalid user id'); } // 获得团队信息 $team = TeamLogic::getTeam($targetId); if (empty($team)) { return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'invalid team id'); } if (TeamLogic::isOwner($uid, $targetId)) { return MyTool::onExit($this, MyConst::STATUS_OK, 'already owner of this team'); } if (TeamLogic::hasMember($uid, $targetId)) { return MyTool::onExit($this, MyConst::STATUS_OK, 'already member of this team'); } // 添加申请 $apply = MaTeamInvitatoin::apply($team->id, $team->name, $user->id, $user->name); try { if (true !== $apply->create()) { return MyTool::onExit($this, MyConst::STATUS_DB, 'join in team apply failed'); } } catch (Exception $e) { return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage()); } // 返回 MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK); return true; }