Skip to content

Commit

Permalink
use slack display name and account
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnywang committed Feb 15, 2020
1 parent bdfd706 commit c207733
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions webdata/controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function saveintroAction()
$intro->update(array(
'data' => json_encode(array(
'display_name' => $_POST['display_name'],
'account' => $_POST['account'],
'keyword' => $_POST['keyword'],
'avatar' => $_POST['avatar'],
'has_voice' => $_POST['record_data'] ? 1 : 0,
Expand All @@ -64,6 +65,7 @@ public function saveintroAction()
'created_by' => $this->view->user->id,
'data' => json_encode(array(
'display_name' => $_POST['display_name'],
'account' => $_POST['account'],
'keyword' => $_POST['keyword'],
'avatar' => $_POST['avatar'],
'has_voice' => $_POST['record_data'] ? 1 : 0,
Expand Down
13 changes: 11 additions & 2 deletions webdata/controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ public function callbackAction()
return $this->alert($obj->error, '/');
}

Pix_Session::set('user_id', $user_id);
Pix_Session::set('user_name', $obj->user->name);
Pix_Session::set('access_token', $access_token);
Pix_Session::set('image', $obj->user->image_512);

$url = sprintf('https://slack.com/api/users.info?token=%s&user=%s', urlencode($access_token), urlencode($user_id));
$obj = json_decode(file_get_contents($url));
if (!$obj->ok) {
return $this->alert($obj->error, '/');
}
$account = $obj->user->name;

Pix_Session::set('user_id', $user_id);
Pix_Session::set('account', $account);
Pix_Session::set('access_token', $access_token);

return $this->redirect($next);
}

Expand Down
25 changes: 13 additions & 12 deletions webdata/views/event/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
<form method="post" action="/event/saveintro/<?= $this->event->id ?>">
<input type="hidden" name="record_data" value="">
<input type="hidden" name="record_length" value="">
Slack 帳號:<?= $this->escape($this->user->name) ?><br>
<?php if (!$this->intro) { ?>
顯示頭像:<img src="<?= $this->escape(Pix_Session::get('image')) ?>" width="128" height="128"><br>
Slack 帳號:<?= $this->escape(Pix_Session::get('account')) ?><br>
<input type="hidden" name="avatar" value="<?= $this->escape(Pix_Session::get('image')) ?>">
顯示名稱:<input type="text" name="display_name" value="<?= $this->escape($this->user->name) ?>"><br>
<input type="hidden" name="account" value="<?= $this->escape(Pix_Session::get('account')) ?>">
<input type="hidden" name="display_name" value="<?= $this->user->name ?>">
顯示頭像:<img src="<?= $this->escape(Pix_Session::get('image')) ?>" width="128" height="128"><br>
顯示名稱:<?= $this->escape($this->user->name) ?><br>
(若想變更頭像或是顯示名稱,請至 slack 變更並在這邊重新登入)<br>
<?php if (!$this->intro) { ?>
三個關鍵字:<input type="text" name="keyword"><br>
錄音:<button id="record">按我錄音</button>
<button id="replay" style="display:none">按我聽錄音</button>
<audio id="replay-audio"></audio>
<span id="record-time">(目前沒有錄音,若不錄音將會以語音念出您的三個關鍵字)</span><br>
<?php } else { ?>
<?php $data = json_decode($this->intro->data) ?>
顯示頭像:<img src="<?= $this->escape($data->avatar) ?>" width="128" height="128"><br>
<input type="hidden" name="avatar" value="<?= $this->escape($data->avatar) ?>">
顯示名稱:<input type="text" name="display_name" value="<?= $this->escape($data->display_name) ?>"><br>
三個關鍵字:<input type="text" name="keyword" value="<?= $this->escape($data->keyword) ?>"><br>
錄音:<button id="record">按我錄音</button>
<button id="replay" style="display:none">按我聽錄音</button>
Expand Down Expand Up @@ -129,11 +129,12 @@ window.onload = function () {
<li class="span2">
<div class="thumbnail">
<img src="<?= $this->escape($data->avatar) ?>" width="128" height="128" alt="">
<h3><?= $this->escape($data->display_name) ?></h3>
<p><?= $this->escape($data->keyword) ?></p>
<?php if ($data->has_voice) { ?>
<p><a href="#" class="btn btn-primary play-voice" data-id="<?= $intro->id ?>">播放自介</a></p>
<?php } ?>
<h3>@<?= $this->escape($data->account) ?></h3>
顯示名稱:<?= $this->escape($data->display_name) ?><br>
<p>關鍵字:<?= $this->escape($data->keyword) ?></p>
<?php if ($data->has_voice) { ?>
<p><a href="#" class="btn btn-primary play-voice" data-id="<?= $intro->id ?>">播放自介</a></p>
<?php } ?>
</li>
<?php } ?>
</ul>
Expand Down

0 comments on commit c207733

Please sign in to comment.