forked from meolu/walle-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wushuiyong
committed
Oct 3, 2015
1 parent
1beff4b
commit c599d84
Showing
22 changed files
with
1,034 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
<?php | ||
/** | ||
* Application parameters | ||
* 亲,为方便大家,已经把必须修改为自己配置的选项已经带上*****了 | ||
* 此配置为测试配置,如果你不想消息泄露,请尽快修改为自己的邮箱smtp | ||
*/ | ||
return [ | ||
'support.email' => '[email protected]', | ||
'support.name' => 'admin', | ||
// ******必须要与config/web.php 中mail模块的username一致***** | ||
'support.email' => '[email protected]', | ||
// 显示发件人的名字,可以随意 | ||
'support.name' => 'service', | ||
|
||
'user.passwordResetTokenExpire' => 3600, | ||
'user.emailConfirmationTokenExpire' => 43200, // 5 days | ||
|
||
// 操作日志目录 | ||
'user.emailConfirmationTokenExpire' => 43200, // 5 days有效 | ||
|
||
// 头像图片后缀 | ||
'user.avatar.extension' => [ | ||
'jpg', 'png', 'jpeg', | ||
], | ||
|
||
// *******操作日志目录******* | ||
'log.dir' => '/tmp/walle/', | ||
// 指定邮箱后缀 | ||
// *******指定公司邮箱后缀******* | ||
'mail-suffix' => [ | ||
'公司邮箱后缀.com', // 限制只有公司同学可注册,可多个 | ||
] | ||
'huamanshu.com', # 支持多个 | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace app\controllers; | ||
|
||
use app\components\Controller; | ||
use app\components\GlobalHelper; | ||
use app\models\User; | ||
|
||
class UserController extends Controller { | ||
|
||
// 头像大小限制200k | ||
const AVATAR_SIZE = 200000; | ||
|
||
public function actionIndex() { | ||
$user = User::findOne($this->uid); | ||
return $this->render('index', [ | ||
'user' => $user, | ||
]); | ||
} | ||
|
||
public function actionAvatar() { | ||
$fileParts = pathinfo($_FILES['avatar']['name']); | ||
if ($_FILES['avatar']['error']) { | ||
$this->renderJson([], -1, '上传附件失败'); | ||
} | ||
if ($_FILES['avatar']['size'] > static::AVATAR_SIZE) { | ||
$this->renderJson([], -1, '文件过大'); | ||
} | ||
if (!in_array(strtolower($fileParts['extension']), \Yii::$app->params['user.avatar.extension'])) { | ||
$this->renderJson([], -1, '上传附件失败,附件格式只支持:' . join(', ', \Yii::$app->params['user.avatar.extension'])); | ||
} | ||
$tempFile = $_FILES['avatar']['tmp_name']; | ||
$baseName = sprintf('%s-%d.%s', date("YmdHis", time()), rand(10, 99), $fileParts['extension']); | ||
$newFile = GlobalHelper::formatAvatar($baseName); | ||
$targetFile = sprintf("%s/web/%s", rtrim(\Yii::$app->basePath, '/'), ltrim($newFile, '/')); | ||
$ret = move_uploaded_file($tempFile, $targetFile); | ||
if ($ret) { | ||
$user = User::findOne($this->uid); | ||
$user->avatar = $baseName; | ||
$ret = $user->save(); | ||
} | ||
|
||
$this->renderJson(['url' => $newFile], !$ret, $ret ?: '更新头像失败'); | ||
} | ||
|
||
} |
Oops, something went wrong.