<?php

/* ========================================================================
 * $Id: register.php 3595 2017-06-11 17:43:30Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
$goto=onez()->gp('goto');
!$goto && $goto=onez()->href('/index.php');
$action=onez()->gp('action');
if($action=='regpost'){
  $nickname=onez()->gp('nickname');
  if($G['this']->option('nickname_maxlength')){
    $nickname_maxlength=$G['this']->option('nickname_maxlength');
    if(onez()->strlen($nickname)>$nickname_maxlength){
      onez()->error('昵称长度不能大于'.$nickname_maxlength.'个字符');
    }
  }
  $qq=onez()->gp('qq');
  $username=onez()->gp('username');
  $password=onez()->gp('password');
  $password2=onez()->gp('password2');
  $password_md5=md5($password);
  if($password!=$password2){
    onez()->error('两次密码不一致');
  }
  $onez=array();
  $onez['nickname']=$nickname;
  $onez['qq']=$qq;
  $onez['username']=$username;
  $G['this']->data()->open('member')->rows("`username`='$onez[username]'")>0 && onez()->error('这个账号已经存在，请更换');
  $onez['password']=$password_md5;
  $onez['grade']='user';
  $userid=$G['this']->data()->open('member')->insert($onez);
  
  onez('cache')->cookie('chat_group',"$userid\t$onez[username]",0);
  onez()->ok('注册成功',$goto);
}
include_once(dirname(__FILE__).'/header.php');
?>
<link rel="stylesheet" href="<?php echo onez('login')->url?>/php/images/signin.css" />
<link rel="stylesheet" href="<?php echo onez('admin')->url?>/assets/css/font-awesome.min.css">
<style>
body{
  background-image:url(<?php echo $baseurl?>/images/bg.jpg);
}
</style>
<div class="signin" style="margin-top:-290px">
	<div class="signin-head"><img src="<?php echo $baseurl?>/images/qq.jpg" alt="" class="img-circle"></div>
	<form class="form-signin" method="post" role="form">
    <p class="form-item">
      <i class="fa fa-user"></i>
      <input type="text" name="username" class="form-control" placeholder="请填写您要注册的登录账号" required autofocus />
    </p>
    <p class="form-item">
      <i class="fa fa-key"></i>
      <input type="password" name="password" class="form-control" placeholder="登录密码" required />
    </p>
    <p class="form-item">
      <i class="fa fa-key"></i>
      <input type="password" name="password2" class="form-control" placeholder="确认登录密码" required />
    </p>
    <p class="form-item">
      <i class="fa fa-user"></i>
      <input type="text" name="nickname" class="form-control" placeholder="请填写您要使用的昵称" required autofocus />
    </p>
    <p class="form-item">
      <i class="fa fa-user"></i>
      <input type="text" name="qq" class="form-control" placeholder="请填写您的QQ号码" required autofocus />
    </p>
		<button class="btn btn-lg btn-success btn-block" type="submit">立即注册</button>
    <input type="hidden" name="action" value="regpost" />
    <div class="" style="padding-top: 10px">
      <div class="pull-left">
        <a href="<?php echo onez()->href('/index.php')?>" target="_top">返回首页</a>
      </div>
      <div class="pull-right">
        <a href="<?php echo onez()->href('/login.php?goto='.urlencode($goto))?>">返回登录页</a>
      </div>
      <div class="clearfix"></div>
    </div>
	</form>
</div>
<script type="text/javascript">
$(function(){
  $('.form-signin').unbind('submit').bind('submit',function(){
    $.post(window.location.href,$(this).serialize(),function(o){
      if(o.error){
        $('.rndcode-img').trigger('click');
        alert(o.error);
      }else{
        location.href=o.goto;
      }
    },'json');
    return false;
  });
});
</script>
<?php 
include_once(dirname(__FILE__).'/footer.php');
