2015-11-05 12:23:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Home\Controller;
|
|
|
|
|
|
|
|
use Think\Controller;
|
|
|
|
|
|
|
|
class UserController extends Controller {
|
|
|
|
public function index() {
|
|
|
|
$data = M ( 'authme' )->select ();
|
|
|
|
dump ( $data );
|
|
|
|
$this->data->$data;
|
|
|
|
$this->display ();
|
|
|
|
}
|
2015-11-06 10:12:15 +00:00
|
|
|
public function Check($username) {
|
|
|
|
$data = M ( 'authme' )->where ( array ('username' => $username ) )->find ();
|
|
|
|
if ($data != null) {
|
|
|
|
$this->success ( "用户已注册!", '', true );
|
|
|
|
} else {
|
|
|
|
$this->error ( "用户未注册!", '', true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function Login($username, $password, $verify = null) {
|
|
|
|
$data = M ( 'authme' )->where ( array ('username' => $username,'password' => md5 ( $password ) ) )->find ();
|
|
|
|
if (IS_POST) {
|
|
|
|
/* 检测验证码 */
|
|
|
|
if (! check_verify ( $verify )) {
|
2015-11-08 15:56:53 +00:00
|
|
|
$this->error ( '验证码输入错误!',"",true );
|
2015-11-06 10:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 12:23:14 +00:00
|
|
|
if ($data != null) {
|
2015-11-06 10:12:15 +00:00
|
|
|
$this->success ( "登录成功!", U ( 'Index/Index' ), true );
|
2015-11-05 12:23:14 +00:00
|
|
|
} else {
|
2015-11-06 10:12:15 +00:00
|
|
|
$this->error ( "登录失败 用户名或密码错误!", U ( 'Index/Login' ), true );
|
2015-11-05 12:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public function Register($username, $password, $ip = '127.0.0.1', $mail = 'authme@citycraft.cn') {
|
|
|
|
$modelAuthMe = M ( 'authme' );
|
2015-11-06 10:12:15 +00:00
|
|
|
$result = $modelAuthMe->where ( array (username => $username ) )->find ();
|
2015-11-05 12:23:14 +00:00
|
|
|
if ($result != null) {
|
2015-11-06 10:12:15 +00:00
|
|
|
$this->ajaxReturn ( array (status => "error",msg => "注册失败,用户已存在!" ) );
|
2015-11-05 12:23:14 +00:00
|
|
|
}
|
|
|
|
$value = array (
|
|
|
|
'username' => $username,
|
2015-11-06 10:12:15 +00:00
|
|
|
'password' => md5 ( $password ),
|
2015-11-05 12:23:14 +00:00
|
|
|
'ip' => $ip,
|
|
|
|
'lastlogin' => '',
|
|
|
|
'x' => '0',
|
|
|
|
'y' => '0',
|
|
|
|
'z' => '0',
|
|
|
|
'world' => 'world',
|
2015-11-06 10:12:15 +00:00
|
|
|
'email' => $mail );
|
2015-11-05 12:23:14 +00:00
|
|
|
$result = $modelAuthMe->save ( $value );
|
|
|
|
if ($result) {
|
2015-11-06 10:12:15 +00:00
|
|
|
$this->ajaxReturn ( array (status => "success",msg => "注册成功!" ) );
|
2015-11-05 12:23:14 +00:00
|
|
|
} else {
|
2015-11-06 10:12:15 +00:00
|
|
|
$this->ajaxReturn ( array (status => "error",msg => "注册失败!" ) );
|
2015-11-05 12:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|