/** * 用户登录 * * @param SignInRequest $request * @return \Illuminate\Http\JsonResponse * @throws \App\Exceptions\SignInException */ public function doSignIn(SignInRequest $request) { $loginId = $request->get('login_id'); $username = $request->get('username'); $email = $request->get('email'); $phone = $request->get('phone'); $password = $request->get('password'); $remember = $request->get('remember'); if ($phone) { $user = UserManager::signInByPhone($phone, $password, $remember); } else { if ($email) { $user = UserManager::signInByEmail($email, $password, $remember); } else { if ($username) { $user = UserManager::signInByUsername($username, $password, $remember); } else { if (Tools::isEmail($loginId)) { $user = UserManager::signInByEmail($loginId, $password, $remember); } else { if (Tools::isPhone($loginId)) { $user = UserManager::signInByPhone($loginId, $password, $remember); } else { $user = UserManager::signInByUsername($loginId, $password, $remember); } } } } } return $this->buildResponse(trans('api.auth.sign_in.success'), Tools::toArray($user)); }
public function getUsersWithPaginate(Request $request) { $perPage = $request->get('num'); if (!is_numeric($perPage) || $perPage < 1 || $perPage > 30) { $perPage = 15; } $users = User::orderBy('id', 'desc')->paginate($perPage); return $this->buildResponse(trans('api.user.paginate.success'), Tools::toArray($users)); }
public function getAmaotoFlow() { $flow = new Collection(); Music::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) { /** @var Music $item */ $flow->push(['type' => 'music', 'data' => $item->toArray()]); }); Album::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) { /** @var Album $item */ $flow->push(['type' => 'album', 'data' => $item->toArray()]); }); $result = $flow->shuffle(); return $this->buildResponse(trans('api.system.get-amaoto-flow.success'), Tools::toArray($result)); }
/** * 用户注册 * * @param $username * @param $email * @param $phone * @param $password * @return User * @throws SignUpException */ public static function signUp($username, $email, $phone, $password) { if (!is_null($username) && self::isUsernameExists($username)) { throw new SignUpException(SignUpException::UsernameExists, ['username' => $username]); } if (!is_null($email) && self::isEmailExists($email)) { throw new SignUpException(SignUpException::EmailExists, ['email' => $email]); } if (!is_null($phone) && self::isPhoneExists($phone)) { throw new SignUpException(SignUpException::PhoneExists, ['phone' => $phone]); } $user = new User(); $user->username = $username; $user->email = Tools::isEmail($email) ? $email : null; $user->phone = Tools::isPhone($phone) ? $phone : null; $user->password = bcrypt($password); $user->save(); return $user; }
public function getAlbumsWithPaginate(Request $request) { $perPage = $request->get('num'); if (!is_numeric($perPage) || $perPage < 1 || $perPage > 30) { $perPage = 15; } $albums = Album::with(['musics' => function ($query) { $query->orderBy('track', 'asc'); }])->orderBy('id', 'desc')->paginate($perPage); return $this->buildResponse(trans('api.album.paginate.success'), Tools::toArray($albums)); }