Commit 08a28d97 authored by xiabin's avatar xiabin

添加生成头像的代码

parent b7f2759f
...@@ -139,12 +139,6 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -139,12 +139,6 @@ class User extends ActiveRecord implements IdentityInterface
return static::findOne(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE]); return static::findOne(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE]);
} }
public static function findByTelephone2($telephone)
{
// return static::findOne(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE]);
return static::find()->select('id,username')->where(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE])
->one();
}
/** /**
* Finds user by password reset token * Finds user by password reset token
......
...@@ -9,16 +9,17 @@ ...@@ -9,16 +9,17 @@
namespace frontend\controllers; namespace frontend\controllers;
use common\libs\Message;
use common\libs\Test; use common\libs\Test;
use common\libs\Utils;
use common\models\BrowseRecord; use common\models\BrowseRecord;
use common\models\Favorite; use common\models\Favorite;
use common\models\Orders; use common\models\Orders;
use common\models\User; use common\models\User;
use yii\base\ErrorException;
use yii\base\Exception;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
use Yii; use Yii;
use yii\helpers\HtmlPurifier;
class UserCenterController extends Controller class UserCenterController extends Controller
{ {
...@@ -56,7 +57,15 @@ class UserCenterController extends Controller ...@@ -56,7 +57,15 @@ class UserCenterController extends Controller
*/ */
public function actionInfo() public function actionInfo()
{ {
return $this->render('info'); $qiniu = Yii::$app->qiniu;
$returnBody = '{"key":"$(key)"}';
//图片上传Token
//$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
$imgPath = 'avatar/' . $qiniu->generateRandomFilePath('$(ext)', 10);
$publicToken = $qiniu->getUploadToken('public', $imgPath, $returnBody);
return $this->render('info', compact('publicToken'));
} }
/** /**
...@@ -93,4 +102,24 @@ class UserCenterController extends Controller ...@@ -93,4 +102,24 @@ class UserCenterController extends Controller
return $this->render('browse_record'); return $this->render('browse_record');
} }
//fe7e7ff7-ef6d-45da-a6f5-ec93792101b4
/**
* 设置头像信息
* @param $key
* @throws \yii\web\ForbiddenHttpException
*/
public function actionSetVatarInfo($key)
{
if (Yii::$app->request->isAjax) {
$user = Yii::$app->user->identity;
$user->avatar = $key;
$user->save();
Utils::ajaxResponse();
} else {
throw new \yii\web\ForbiddenHttpException('非法请求');
}
}
} }
\ No newline at end of file
...@@ -5,13 +5,16 @@ ...@@ -5,13 +5,16 @@
* Date: 2016/9/27 * Date: 2016/9/27
* Time: 下午4:16 * Time: 下午4:16
*/ */
\frontend\assets\AppAsset::addScript($this, '@web/assets/user_center_info.js') \frontend\assets\AppAsset::addScript($this, '@web/assets/user_center_info.js');
$url = Yii::$app->qiniu->storages['public']['url'];
?> ?>
<h1>user-center/info</h1> <h1>user-center/info</h1>
<img <div id="avatar-uploader-container"><img id="avatar-uploader" token="<?= $publicToken ?>"
src="<?php echo Yii::$app->user->identity->avatar === '' ? \frontend\assets\AppAsset::getStaticUrl('img/avatar.jpg') : Yii::$app->user->identity->avatar ?>"> src="<?php echo Yii::$app->user->identity->avatar === '' ? \frontend\assets\AppAsset::getStaticUrl('img/avatar.jpg') : $url . Yii::$app->user->identity->avatar ?>">
</div>
<p> <p>
You may change the content of this page by modifying You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>. the file <code><?= __FILE__; ?></code>.
......
...@@ -2,3 +2,84 @@ ...@@ -2,3 +2,84 @@
* Created by xiabin on 2016/9/29. * Created by xiabin on 2016/9/29.
*/ */
layer.msg('玩命提示中'); layer.msg('玩命提示中');
var token = $('#avatar-uploader').attr('token');
require.ensure('../single-lib/plupload/plupload.full.min.js', function () {
require('script!../single-lib/plupload/plupload.full.min.js');
var uploader = new plupload.Uploader({
runtimes: 'html5,flash,html4',
browse_button: 'avatar-uploader',
url: "http://upload.qiniu.com/",
multipart_params: {
token: token
},
max_file_size: '5MB',
flash_swf_url: __CDN_URL__ + 'assets/single-lib/plupload/Moxie.swf',
max_retries: 0,
dragdrop: false,
multi_selection: false,
auto_start: true,
init: {
'FilesAdded': function (up, files) {
// plupload.each(files, function (file) {
// ready.find(".upload-info-size").text(filesize(file.origSize));
// ready.find("h3").text(file.name);
// });
//
// container.find(".upload-video-btn").hide();
// ready.show();
//
up.start();
up.disableBrowse();
//
// startTime = (new Date()).getTime();
},
'BeforeUpload': function (up, file) {
// 每个文件上传前,处理相关的事情
},
'UploadProgress': function (up, file) {
// progress.css("width", file.percent + "%");
// infoProgress.text(file.percent);
// infoSpeed.text(filesize(up.total.bytesPerSec));
//
// // var avgSpeed = file.loaded / (((new Date()).getTime() - startTime) / 1000);
//
// var sizeRemain = file.origSize - file.loaded;
// var leftSeconds = sizeRemain / up.total.bytesPerSec;
// var toDate = new Date();
// toDate.setTime((new Date()).getTime() + leftSeconds * 1000);
// infoRemain.text(moment(toDate).toNow(true));
// infoProgress.text(file.percent);
// $("#" + file.id + " .attachup-list-element-status").html("上传中 - " + file.percent + "%");
},
'FileUploaded': function (up, file, info) {
// 每个文件上传成功后,处理相关的事情
// 其中info是文件上传成功后,服务端返回的json,形式如:
// {
// "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
// "key": "gogopher.jpg"
// }
// 查看简单反馈
var res = JSON.parse(info.response);
var url = __QINIU_URL__ + res.key;
$.getJSON(__BASE_URL__ + 'user-center/set-vatar-info?key=' + res.key, function (reponse) {
if (reponse.status) {
window.location.reload();
}
}).error(function () {
layer.alert('设置头像信息接口错误', {'icon': 2, 'title': '提示'});
});
},
'Error': function (up, err, errTip) {
//上传出错时,处理相关的事情
},
'UploadComplete': function () {
//队列文件处理完毕后,处理相关的事情
}
}
});
uploader.init()
});
...@@ -123,8 +123,8 @@ if (process.env.NODE_ENV === 'production') { ...@@ -123,8 +123,8 @@ if (process.env.NODE_ENV === 'production') {
config.plugins = config.plugins.concat([ config.plugins = config.plugins.concat([
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__BASE_URL__: JSON.stringify('http://dev.zuiketang.com/'), __BASE_URL__: JSON.stringify('http://dev.zuiketang.com/'),
__CDN_URL__: JSON.stringify('http://dev.zuiketang.com/') __CDN_URL__: JSON.stringify('http://dev.zuiketang.com/'),
__QINIU_URL__: JSON.stringify('http://dev.qdn.pp.cc/'),
}), }),
]); ]);
// config.devtool = 'source-map' // config.devtool = 'source-map'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment