You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
5.4 KiB
164 lines
5.4 KiB
<?php
|
|
namespace apps\user\controllers;
|
|
|
|
use apps\base\controllers\FrontendController;
|
|
|
|
class ProfileController extends FrontendController
|
|
{
|
|
|
|
public $user_id;
|
|
|
|
public $email;
|
|
|
|
public $mobile;
|
|
|
|
public $sex;
|
|
|
|
/**
|
|
* 构造函数
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
L(require (ROOT_PATH . 'source/language/' . C('shop.lang') . '/user.php'));
|
|
$file = array(
|
|
'passport',
|
|
'clips'
|
|
);
|
|
$this->load_helper($file);
|
|
// 属性赋值
|
|
$this->user_id = $_SESSION['user_id'];
|
|
// 验证登录
|
|
$this->actionchecklogin();
|
|
$this->assign('lang', L());
|
|
}
|
|
|
|
/**
|
|
* 频道页
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
$this->parameter();
|
|
$sql = "SELECT user_id,user_name,sex FROM {pre}users WHERE user_id = " . $this->user_id;
|
|
$user_info = $this->db->getRow($sql);
|
|
$this->assign("user_sex", $user_info['sex']);
|
|
$this->display('user_detail');
|
|
}
|
|
// 修改个人资料
|
|
public function actionEditProfile()
|
|
{
|
|
$this->parameter();
|
|
if (IS_POST) {
|
|
if (! empty($this->sex)) {
|
|
$update = " sex = '" . $this->sex . "'";
|
|
}
|
|
$where = " WHERE user_id = '" . $this->user_id . "'";
|
|
if (isset($update) && isset($where)) {
|
|
$sql = "UPDATE {pre}users SET $update $where";
|
|
$this->db->query($sql);
|
|
}
|
|
$info = get_user_default($this->user_id);
|
|
echo json_encode($info);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改手机
|
|
*/
|
|
public function actionUserEditMobile()
|
|
{
|
|
$this->parameter();
|
|
$sql = "SELECT user_id,user_name,mobile_phone FROM {pre}users WHERE user_id = " . $this->user_id;
|
|
$user_info = $this->db->getRow($sql);
|
|
if (IS_POST && I('sms_signin') == 1) {
|
|
echo '12321';exit;
|
|
$sms_code = I('sms_code');
|
|
if ($sms_code !== $_SESSION['sms_code']) {
|
|
show_message("您输入的验证码有误");
|
|
exit();
|
|
}
|
|
if (empty($this->mobile)) {
|
|
show_message("请输入手机号");
|
|
exit();
|
|
}
|
|
|
|
if (!empty($user_info)) {
|
|
$sql = "UPDATE {pre}users SET mobile_phone = '" . $this->mobile . "' WHERE user_id = '" . $this->user_id . "'";
|
|
$this->db->query($sql);
|
|
}
|
|
}
|
|
if(IS_POST && I('sms_signin') == 0){
|
|
if(!empty($this->mobile)){
|
|
$sql = "UPDATE {pre}users SET mobile_phone = '" . $this->mobile . "' WHERE user_id = '" . $this->user_id . "'";
|
|
$up = $this->db->query($sql);
|
|
ecs_header("Location: " . U('user/profile/index'));
|
|
}
|
|
}
|
|
$_SESSION['sms_code'] = $sms_code = md5(mt_rand(1000, 9999));
|
|
$this->assign("sms_code", $sms_code);
|
|
$this->assign("mobile", $user_info['mobile_phone']);
|
|
$this->assign("sms_signin", C('shop.sms_signin'));
|
|
$this->assign("page_title","修改手机" );
|
|
$this->display('user_edit_mobile');
|
|
}
|
|
|
|
/**
|
|
* 修改邮箱
|
|
*/
|
|
public function actionUserEditEmail()
|
|
{
|
|
$this->parameter();
|
|
$sql = "SELECT user_id,email FROM {pre}users WHERE user_id = " . $this->user_id;
|
|
$user_info = $this->db->getRow($sql);
|
|
if (IS_POST) {
|
|
if (! empty($this->email)) {
|
|
$sql = "UPDATE {pre}users SET email = '" . $this->email . "' WHERE user_id = '" . $this->user_id . "'";
|
|
$this->db->query($sql);
|
|
}
|
|
ecs_header("Location: " . U('user/profile/index'));
|
|
}
|
|
$this->assign('emails', $user_info['email']);
|
|
$this->assign("page_title","修改邮箱" );
|
|
$this->display('user_edit_email');
|
|
}
|
|
|
|
private function parameter()
|
|
{
|
|
$this->user_id = $_SESSION['user_id'];
|
|
if (empty($this->user_id)) {
|
|
ecs_header("Location: ./\n");
|
|
}
|
|
$this->mobile = I('mobile');
|
|
$this->sex = I('sex');
|
|
$this->email = I('email');
|
|
$this->postbox = I('postbox');
|
|
$this->assign('info', get_user_default($this->user_id)); // 自定义导航栏
|
|
}
|
|
|
|
// 发送短信
|
|
public function actionSendSms()
|
|
{
|
|
$mobile = I('mobile');
|
|
$sms_code = I('sms_code');
|
|
if (! empty($mobile) && ! empty($sms_code)) {
|
|
// $content = "您的验证码是:" .$sms_code. ",请不要把验证码泄露给其他人,如非本人操作,可不用理会";
|
|
$content = "您的验证码是:" . $sms_code . ",请不要把验证码泄露给其他人,如非本人操作,可不用理会";
|
|
// $content= array('phones'=>$mobile,'content'=>$content);
|
|
send_sms($mobile, $content);
|
|
}
|
|
}
|
|
/**
|
|
* 验证是否登录
|
|
*/
|
|
public function actionchecklogin(){
|
|
if(!$this->user_id){
|
|
$url = urlencode(__HOST__ . $_SERVER['REQUEST_URI']);
|
|
if(IS_POST) {
|
|
$url = urlencode($_SERVER['HTTP_REFERER']);
|
|
}
|
|
ecs_header("Location: ".U('user/login/index',array('back_act'=>$url)));
|
|
exit;
|
|
}
|
|
}
|
|
}
|