public function doRegister(Request $request)
 {
     $validator = Validator::make($data = $request->all(), Admin::$rules, Admin::$messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($validator->passes()) {
         $confirmation_code = Str::quickRandom(30);
         $admin = new Admin();
         $admin->fullname = ucwords($request->fullname);
         $admin->mobile_no = $request->mobile_no;
         $admin->email = $request->email;
         $admin->password = bcrypt($request->password);
         $admin->confirmation_code = $confirmation_code;
         $data = ['confirmation_code' => $confirmation_code, 'username' => $request->username, 'password' => $request->password, 'mobile_no' => $request->mobile_no];
         Basehelper::sendSMS($request->mobile_no, 'Hello ' . $request->username . ', you have successfully registere. Your username is ' . $request->username . ' and password is ' . $request->password);
         // Mail::send('emails.verify', $data, function($message) use ($admin, $data){
         // 	$message->from('no-reply@employment_bank', 'Employment Bank');
         //     	$message->to(Input::get('email'), $admin->name)
         //         	->subject('Verify your email address');
         // });
         if (!$admin->save()) {
             return Redirect::back()->with('message', 'Error while creating your account!<br> Please contact Technical Support');
         }
         return Redirect::route('admin.login')->with('message', 'Account has been created!<br>Now Check your email address to verify your account by checking your spam folder or inboxes for verification link after that you can login');
         //sendConfirmation() Will go the email and sms as needed
     } else {
         return Redirect::back()->withInput()->withErrors($validation);
         // ->with('message', 'There were validation errors.');
     }
 }
示例#2
0
 /**
  * @param UploadAvatar $command
  * @return \Flarum\Core\User
  * @throws \Flarum\Core\Exception\PermissionDeniedException
  */
 public function handle(UploadAvatar $command)
 {
     $actor = $command->actor;
     $user = $this->users->findOrFail($command->userId);
     if ($actor->id !== $user->id) {
         $this->assertCan($actor, 'edit', $user);
     }
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
     $command->file->moveTo($tmpFile);
     $file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
     $this->validator->assertValid(['avatar' => $file]);
     $manager = new ImageManager();
     $manager->make($tmpFile)->fit(100, 100)->save();
     $this->events->fire(new AvatarWillBeSaved($user, $actor, $tmpFile));
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
     if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
         $mount->delete($file);
     }
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $user->changeAvatarPath($uploadName);
     $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
     $user->save();
     $this->dispatchEventsFor($user, $actor);
     return $user;
 }
 /**
  * @param UploadAvatar $command
  * @return \Flarum\Core\Users\User
  * @throws \Flarum\Core\Exceptions\PermissionDeniedException
  */
 public function handle(UploadAvatar $command)
 {
     $actor = $command->actor;
     $user = $this->users->findOrFail($command->userId);
     // Make sure the current user is allowed to edit the user profile.
     // This will let admins and the user themselves pass through, and
     // throw an exception otherwise.
     if ($actor->id !== $user->id) {
         $user->assertCan($actor, 'edit');
     }
     $tmpFile = tempnam(sys_get_temp_dir(), 'avatar');
     $command->file->moveTo($tmpFile);
     $manager = new ImageManager();
     $manager->make($tmpFile)->fit(100, 100)->save();
     event(new AvatarWillBeSaved($user, $actor, $tmpFile));
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
     if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
         $mount->delete($file);
     }
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $user->changeAvatarPath($uploadName);
     $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function data(ServerRequestInterface $request, Document $document)
 {
     $this->assertAdmin($request->getAttribute('actor'));
     $file = array_get($request->getUploadedFiles(), 'favicon');
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
     $file->moveTo($tmpFile);
     $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
     if ($extension !== 'ico') {
         $manager = new ImageManager();
         $encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->encode('png');
         file_put_contents($tmpFile, $encodedImage);
         $extension = 'png';
     }
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
     if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
         $mount->delete($file);
     }
     $uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
     $mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
     $this->settings->set('favicon_path', $uploadName);
     return parent::data($request, $document);
 }
示例#5
0
 /**
  * Create a document.
  *
  * @param DocumentRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(DocumentRequest $request)
 {
     $document = new Document($request->only(['group', 'published']));
     $document->save();
     $attachment = $document->attachments()->save(new Attachment(['name' => $request->input('name'), 'file_name' => Str::quickRandom(6) . '.' . $request->file('attachment')->guessExtension(), 'mime_type' => $request->file('attachment')->getMimeType(), 'size' => $request->file('attachment')->getSize()]));
     $request->file('attachment')->move($attachment->getDirectory(), $attachment->getAttribute('file_name'));
     return Response::redirectToRoute('documents.index');
 }
示例#6
0
 public function saveImage($tmpFile)
 {
     $dir = date('Ym/d');
     $mount = new MountManager(['source' => new Filesystem(new LocalFS(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new LocalFS(public_path('assets/uploads')))]);
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$dir}/{$uploadName}");
     return $this->config['urlPrefix'] . 'uploads/' . $dir . '/' . $uploadName;
 }
示例#7
0
 /**
  * Create a new zinc.
  *
  * @param ZincRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(ZincRequest $request)
 {
     $zinc = Zinc::create(array_merge($request->only(['year', 'month', 'topic']), $this->getPublished($request)));
     foreach ($request->file('image', []) as $file) {
         $zinc->addMedia($file)->setFileName(Str::quickRandom(8) . '.' . $file->guessExtension())->toCollection('images-zinc', 'media.zinc');
     }
     return redirect()->route('zinc.manage.index');
 }
示例#8
0
 public function put($contents, $callback, $extension = '')
 {
     $path = $this->tempPath . '/' . Str::quickRandom(32) . $extension;
     $this->filesystem->put($path, $contents);
     $result = $callback($path);
     $this->filesystem->delete($path);
     return $result;
 }
示例#9
0
 public function saveImage($tmpFile)
 {
     $upManager = new UploadManager();
     $auth = new Auth($this->config['accessToken'], $this->config['secretToken']);
     $token = $auth->uploadToken($this->config['bucketName']);
     $uploadName = date('Y/m/d/') . Str::lower(Str::quickRandom()) . '.jpg';
     list($ret, $error) = $upManager->put($token, $uploadName, file_get_contents($tmpFile));
     if (!$ret) {
         throw new Exception($error->message());
     }
     return rtrim($this->config['baseUrl'], '/') . '/' . $uploadName;
 }
示例#10
0
 public function saveImage($tmpFile)
 {
     $resp = [];
     $filename = date('Y/m/d/') . Str::quickRandom() . '.jpg';
     try {
         $resp = $this->http->request('PUT', $filename, ['header' => ['mkdir' => true], 'body' => fopen($tmpFile, 'r')]);
     } catch (RequestException $e) {
         $resp = $e->getResponse();
         throw new Exception('HTTP ' . $resp->getStatusCode() . ' ' . $resp->getReasonPhrase() . "\n" . $resp->getBody()->getContents());
     }
     return rtrim($this->config['baseUrl'], '/') . '/' . $filename;
 }
示例#11
0
 /**
  * Set up a new demo user and log in.
  *
  * @return BackendAuth
  */
 protected function newDemoUser()
 {
     $demoManager = DemoManager::instance();
     $login = Str::quickRandom(Config::get('krisawzm.demomanager::username_length', 10));
     if (!$demoManager->copyTheme($login)) {
         return false;
     }
     $user = User::create(['email' => $login . '@' . $login . '.tld', 'login' => $login, 'password' => $login, 'password_confirmation' => $login, 'first_name' => ucfirst($login), 'last_name' => 'Demo', 'permissions' => $this->getPermissions(), 'is_activated' => true]);
     BackendAuth::login($user);
     UserCounter::instance()->inc();
     return $user;
 }
示例#12
0
 /**
  *  Hijack Eloquent's setAttribute to create a Language Entry, or update the existing one, when setting the value of this attribute.
  *
  *  @param  string  $attribute    Attribute name
  *  @param  string  $value  Text value in default locale.
  *  @return void
  */
 public function setAttribute($attribute, $value)
 {
     if ($this->isTranslatable($attribute) && !empty($value)) {
         // If a translation code has not yet been set, generate one:
         if (!$this->translationCodeFor($attribute)) {
             $reflected = new \ReflectionClass($this);
             $group = 'translatable';
             $item = strtolower($reflected->getShortName()) . '.' . strtolower($attribute) . '.' . Str::quickRandom();
             $this->attributes["{$attribute}_translation"] = "{$group}.{$item}";
         }
     }
     return parent::setAttribute($attribute, $value);
 }
示例#13
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback($provider)
 {
     $providerUser = Socialite::driver($provider)->user();
     $user = User::firstOrNew(['email' => $providerUser->getEmail()]);
     if (!$user->exists) {
         $user->first_name = $providerUser->user['name']['givenName'];
         $user->last_name = $providerUser->user['name']['familyName'];
         $user->password = bcrypt(\Illuminate\Support\Str::quickRandom());
         $user->save();
     }
     try {
         Auth::login($user, true);
     } catch (Exception $ex) {
         return redirect()->intended('/');
     }
     return redirect()->intended('home');
 }
示例#14
0
 public function handle(Request $request)
 {
     $images = $request->http->getUploadedFiles()['images'];
     $results = [];
     foreach ($images as $image_key => $image) {
         $tmpFile = tempnam(sys_get_temp_dir(), 'image');
         $image->moveTo($tmpFile);
         $urlGenerator = app('Flarum\\Http\\UrlGeneratorInterface');
         $dir = 'uploads/' . date('Ym/d');
         $path = './assets/' . $dir;
         $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($path))]);
         $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
         $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
         $results['img_' . $image_key] = Core::url() . '/assets/' . $dir . '/' . $uploadName;
     }
     return new JsonResponse($results);
 }
示例#15
0
 protected function getFiles($type, Closure $callback)
 {
     $dir = $this->getAssetDirectory();
     if (!($revision = $this->getRevision())) {
         $revision = Str::quickRandom();
         $this->putRevision($revision);
     }
     $lastModTime = 0;
     foreach ($this->files[$type] as $file) {
         $lastModTime = max($lastModTime, filemtime($file));
     }
     $debug = 0;
     // $debug = 1;
     if (!file_exists($file = $dir . '/' . $this->name . '-' . $revision . '.' . $type) || filemtime($file) < $lastModTime || $debug) {
         $this->storage->put($file, $callback());
     }
     return [$file];
 }
示例#16
0
 public function getFile()
 {
     $revision = $this->getRevision();
     $lastModTime = 0;
     foreach ($this->files as $file) {
         $lastModTime = max($lastModTime, filemtime($file));
     }
     $ext = pathinfo($this->filename, PATHINFO_EXTENSION);
     $file = $this->path . '/' . substr_replace($this->filename, '-' . $revision, -strlen($ext) - 1, 0);
     if (!($exists = file_exists($file)) || filemtime($file) < $lastModTime) {
         if ($exists) {
             unlink($file);
         }
         $revision = Str::quickRandom();
         $this->putRevision($revision);
         $file = $this->path . '/' . substr_replace($this->filename, '-' . $revision, -strlen($ext) - 1, 0);
         file_put_contents($file, $this->compile());
     }
     return $file;
 }
 public function handle(UploadAvatarCommand $command)
 {
     $user = $this->users->findOrFail($command->userId);
     // Make sure the current user is allowed to edit the user profile.
     // This will let admins and the user themselves pass through, and
     // throw an exception otherwise.
     $user->assertCan($command->actor, 'edit');
     $manager = new ImageManager(array('driver' => 'imagick'));
     $manager->make($command->file->getRealPath())->fit(100, 100)->save();
     $filename = $command->file->getFilename();
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $mount = new MountManager(['source' => new Filesystem(new Local($command->file->getPath())), 'target' => $this->uploadDir]);
     if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
         $mount->delete($file);
     }
     $user->changeAvatarPath($uploadName);
     event(new AvatarWillBeUploaded($user, $command));
     $mount->move("source://{$filename}", "target://{$uploadName}");
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
示例#18
0
 /**
  * 微信卡卷签名
  * @return json
  */
 public function card()
 {
     $validator = Validator::make(Request::input(), ['cardIds' => 'required|array']);
     if ($validator->fails()) {
         return Response::json($validator->errors()->first(), 400);
     }
     $cardIds = Request::input('cardIds');
     $wxConfig = Config::get('wxconfig');
     $wx = Wx::getInstance($wxConfig['appid'], $wxConfig['secret']);
     $cardList = [];
     foreach ($cardIds as $cardId) {
         $cardId = trim($cardId);
         $timestamp = time();
         $nonceStr = Str::quickRandom(32);
         $signature = $wx->getCardSignature($cardId, $timestamp, $nonceStr);
         if (!$signature) {
             return Response::json(['errcode' => 5001, 'errmsg' => '签名失败!']);
         }
         $cardConfig = ['cardId' => $cardId, 'cardExt' => json_encode(['signature' => $signature, 'timestamp' => $timestamp, 'nonce_str' => $nonceStr])];
         array_push($cardList, $cardConfig);
     }
     return Response::json(['errcode' => 0, 'data' => $cardList]);
 }
示例#19
0
 protected function prepareUri($uri)
 {
     return is_null($uri) ? Str::quickRandom() : $uri;
 }
示例#20
0
 public function genPass()
 {
     return Str::lower(Str::quickRandom(12));
 }
示例#21
0
 /**
  * Generate a "random" alpha-numeric string
  **/
 public function quickRandom($length = 16)
 {
     $this->value = Str::quickRandom($length);
     return $this;
 }
示例#22
0
 /**
  * Generates a hash for use in the webhook URL.
  *
  * @return void
  */
 public function generateHash()
 {
     $this->attributes['hash'] = Str::quickRandom(30);
 }
 /**
  * Handles the command execution.
  *
  * @param UploadImage $command
  * @return null|string
  *
  * @todo check permission
  */
 public function handle(UploadImage $command)
 {
     // check if the user can upload images, otherwise return
     $this->assertCan($command->actor, 'flagrow.image.upload');
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'image');
     $command->file->moveTo($tmpFile);
     $file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
     // validate the file
     $this->validator->maxFileSize = $this->settings->get('flagrow.image-upload.maxFileSize', 2048);
     $this->validator->assertValid(['image' => $file]);
     // resize if enabled
     if ($this->settings->get('flagrow.image-upload.mustResize')) {
         $manager = new ImageManager();
         $manager->make($tmpFile)->fit($this->settings->get('flagrow.image-upload.resizeMaxWidth', 100), $this->settings->get('flagrow.image-upload.resizeMaxHeight', 100))->save();
     }
     $image = (new Image())->forceFill(['user_id' => $command->actor->id, 'upload_method' => $this->settings->get('flagrow.image-upload.uploadMethod', 'local'), 'created_at' => Carbon::now(), 'file_name' => sprintf('%d-%s.%s', $command->actor->id, Str::quickRandom(), $file->guessExtension() ?: 'jpg'), 'file_size' => $file->getSize()]);
     // fire the Event ImageWillBeSaved, which can be extended and/or modified elsewhere
     $this->events->fire(new ImageWillBeSaved($command->actor, $image, $file));
     $tmpFilesystem = new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME)));
     $meta = $this->upload->uploadContents($image->file_name, $tmpFilesystem->readAndDelete(pathinfo($tmpFile, PATHINFO_BASENAME)));
     if ($meta) {
         $image->file_url = array_get($meta, 'url');
         if ($image->isDirty()) {
             $image->save();
         }
         return $image;
     }
     return false;
 }
 /**
  * Generate a random key for the JWT Auth secret.
  *
  * @return string
  */
 protected function getRandomKey()
 {
     return Str::quickRandom(32);
 }
示例#25
0
 private function saveAvatarFromUrl(User $user, $url)
 {
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
     $manager = new ImageManager();
     $manager->make($url)->fit(100, 100)->save($tmpFile);
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
     $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
     $user->changeAvatarPath($uploadName);
     $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
 }
示例#26
0
 /**
  * Get a unique id (jti) for the token.
  *
  * @return string
  */
 protected function jti()
 {
     return md5(sprintf('%s.%s', $this->claims->toJson(), Str::quickRandom()));
 }
 public function testStringQuickRandom()
 {
     $str1 = Str::quickRandom();
     $str2 = Str::length($str1);
     $this->assertEquals($str2, 16);
     $str1 = Str::quickRandom(3);
     $str2 = Str::length($str1);
     $this->assertEquals($str2, 3);
 }
示例#28
0
 /**
  * @param UploadAvatar $command
  * @return \Flarum\Core\User
  * @throws \Flarum\Core\Exception\PermissionDeniedException
  */
 public function handle(UploadAvatar $command)
 {
     $actor = $command->actor;
     $user = $this->users->findOrFail($command->userId);
     if ($actor->id !== $user->id) {
         $this->assertCan($actor, 'edit', $user);
     }
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
     $command->file->moveTo($tmpFile);
     try {
         $file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
         $this->validator->assertValid(['avatar' => $file]);
         $manager = new ImageManager();
         // Explicitly tell Intervention to encode the image as JSON (instead of having to guess from the extension)
         $encodedImage = $manager->make($tmpFile)->fit(100, 100)->encode('jpg', 100);
         file_put_contents($tmpFile, $encodedImage);
         $this->events->fire(new AvatarWillBeSaved($user, $actor, $tmpFile));
         $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
         if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
             $mount->delete($file);
         }
         $uploadName = Str::lower(Str::quickRandom()) . '.jpg';
         $user->changeAvatarPath($uploadName);
         $mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
         $user->save();
         $this->dispatchEventsFor($user, $actor);
         return $user;
     } catch (Exception $e) {
         @unlink($tmpFile);
         throw $e;
     }
 }
示例#29
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //make validations
     $validator = Validator::make($request->all(), ['name' => 'required', 'email' => 'array']);
     $validator->each('email', ['email']);
     if ($validator->fails()) {
         return redirect('room/create')->withErrors($validator)->withInput()->with('validation_err', true);
     }
     $room = new Room();
     $room->name = $request->input('name');
     $room->recording = empty($request->input('recording')) ? 0 : 1;
     $room->public = empty($request->input('public')) ? 0 : 1;
     $room->att_pass = Str::quickRandom(8);
     $room->mod_pass = Str::quickRandom(8);
     //add owner
     $user = Auth::User();
     $room->owner = $user->id;
     //check if meeting id exists
     \DB::transaction(function () use($room) {
         //check for unique access_pin and meeting id
         do {
             $bbb_meeting_id = Str::quickRandom(8);
         } while (Room::where('bbb_meeting_id', '=', $bbb_meeting_id)->count() != 0);
         do {
             $access_pin = mt_rand(0, 999999);
         } while (Room::where('access_pin', '=', $access_pin)->count() != 0);
         $room->bbb_meeting_id = $bbb_meeting_id;
         $room->access_pin = $access_pin;
         $room->save();
     });
     //extract emails
     /*$mails = preg_split('/\r\n|\n|\r/', $request->input('participants'));
     	$part_mails = array();
     	foreach($mails as $mail){
     		$part_mail = filter_var($mail, FILTER_VALIDATE_EMAIL);
     		if($part_mail){
     			$participant = new Participant();
     			$participant->mail = $part_mail;
     			$participant->room_id = $room->id;
     			$participant->save();
     		}
     	}*/
     $emails = $request->input('email');
     $moderators = $request->input('moderator');
     if (!$moderators) {
         $moderators = array();
     }
     if (is_array($emails)) {
         foreach ($emails as $email) {
             $participant = new Participant();
             $participant->mail = $email;
             $participant->room_id = $room->id;
             if (in_array($email, $moderators)) {
                 $participant->moderator = 1;
             }
             $participant->save();
         }
     }
     return Redirect::action('roomController@own');
 }