|
@@ -0,0 +1,218 @@
|
|
|
+<?php
|
|
|
+namespace User\Src;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+class Info
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 获取验证码
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getCode()
|
|
|
+ {
|
|
|
+ return Dever::load('sms/api.sendCode', 'code', $this->getMobile());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测验证码
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function checkCode()
|
|
|
+ {
|
|
|
+ return Dever::load('sms/api.checkCode', 'code', $this->getMobile(), Dever::input('code'), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取手机号
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function getMobile()
|
|
|
+ {
|
|
|
+ $rule = Dever::rule('mobile');
|
|
|
+
|
|
|
+ $mobile = Dever::input('mobile');
|
|
|
+
|
|
|
+ if (!$mobile) {
|
|
|
+ Dever::alert('手机号不能为空');
|
|
|
+ }
|
|
|
+ if (!preg_match($rule, $mobile)) {
|
|
|
+ Dever::alert('请填写正确的手机号');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $mobile;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录以及注册
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function login()
|
|
|
+ {
|
|
|
+ $password = Dever::input('password');
|
|
|
+ if ($password) {
|
|
|
+ $password = sha1($password);
|
|
|
+ $param['mobile'] = $this->getMobile();
|
|
|
+ } else {
|
|
|
+ $param['mobile'] = $this->checkCode();
|
|
|
+ }
|
|
|
+ $param['project_id'] = Dever::input('project_id', 1);
|
|
|
+ $info = Dever::db('passport/user')->one($param);
|
|
|
+ if ($info) {
|
|
|
+ if ($password != $info['password']) {
|
|
|
+ Dever::alert('您的账号或密码错误');
|
|
|
+ }
|
|
|
+ $uid = $info['id'];
|
|
|
+ } else {
|
|
|
+ $param['system_source'] = Dever::input('system_source', 1);
|
|
|
+ $param['username'] = Dever::input('username');
|
|
|
+ if (!$param['username']) {
|
|
|
+ $param['username'] = Dever::hide($param['mobile']);
|
|
|
+ }
|
|
|
+ if ($password) {
|
|
|
+ $param['password'] = $password;
|
|
|
+ }
|
|
|
+ $uid = Dever::db('passport/user')->insert($param);
|
|
|
+ if ($uid) {
|
|
|
+ Dever::score($uid, 'reg', '账号注册');
|
|
|
+ if (Dever::project('message')) {
|
|
|
+ $project = Dever::db('user/project')->find($param['project_id']);
|
|
|
+ $content = '亲爱的' . $param['username'] . ',欢迎来到' . $project['name'];
|
|
|
+ Dever::load('message/lib/data')->push(-1, $uid, '欢迎语', $content, 1);
|
|
|
+ }
|
|
|
+ $invite = Dever::input('invite');
|
|
|
+ if ($invite && Dever::project('invite')) {
|
|
|
+ Dever::load('invite/api')->setRelation($uid, false, $invite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 记录登录日志
|
|
|
+ $log['uid'] = $uid;
|
|
|
+ $log['project_id'] = $param['project_id'];
|
|
|
+ $log['system_source'] = $param['system_source'];
|
|
|
+ Dever::db('user/login')->insert($log);
|
|
|
+
|
|
|
+ Dever::load('user/lib/info')->setProject($uid, $param['project_id']);
|
|
|
+ return Dever::load('user/lib/info')->getSign($uid);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户信息
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function update()
|
|
|
+ {
|
|
|
+ $uid = Dever::load('user/lib/info')->check();
|
|
|
+ $name = Dever::input('username');
|
|
|
+ $avatar = Dever::input('avatar');
|
|
|
+ $sex = Dever::input('sex');
|
|
|
+ $province = Dever::input('province');
|
|
|
+ $city = Dever::input('city');
|
|
|
+ $country = Dever::input('country');
|
|
|
+
|
|
|
+ $info = Dever::load('passport/user-one', $uid);
|
|
|
+ if ($info) {
|
|
|
+ $update['username'] = $name;
|
|
|
+ $update['avatar'] = $avatar;
|
|
|
+ $update['sex'] = $sex;
|
|
|
+ $update['province'] = $province;
|
|
|
+ $update['country'] = $country;
|
|
|
+ $update['city'] = $city;
|
|
|
+ if ($country && $province && $city) {
|
|
|
+ $update['area'] = $country . ',' . $province . ',' . $city;
|
|
|
+ }
|
|
|
+
|
|
|
+ $update['where_id'] = $uid;
|
|
|
+ Dever::load('passport/user-update', $update);
|
|
|
+ } else {
|
|
|
+ Dever::alert('无效的用户id,请重新登录');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Dever::db('passport/user')->one(array('id' => $uid, 'clear' => true));
|
|
|
+
|
|
|
+ return Dever::load('user/lib/info')->getSign($uid, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改手机号
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function updateMobile()
|
|
|
+ {
|
|
|
+ $uid = $this->check();
|
|
|
+ $mobile = $this->checkCode();
|
|
|
+
|
|
|
+ $info = Dever::load('passport/user-one', $uid);
|
|
|
+
|
|
|
+ if ($info) {
|
|
|
+ $update['mobile'] = $mobile;
|
|
|
+ $update['where_id'] = $uid;
|
|
|
+ Dever::load('passport/user-update', $update);
|
|
|
+ } else {
|
|
|
+ Dever::alert('更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Dever::load('user/lib/info')->getSign($uid);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改头像
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function updateAvatar()
|
|
|
+ {
|
|
|
+ $uid = $this->check();
|
|
|
+ $avatar = Dever::input('avatar');
|
|
|
+
|
|
|
+ $info = Dever::load('passport/user-one', $uid);
|
|
|
+
|
|
|
+ if ($info) {
|
|
|
+ $update['avatar'] = $avatar;
|
|
|
+ $update['where_id'] = $uid;
|
|
|
+ Dever::load('passport/user-update', $update);
|
|
|
+ } else {
|
|
|
+ Dever::alert('更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Dever::load('user/lib/info')->getSign($uid);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function updatePassword()
|
|
|
+ {
|
|
|
+ $uid = $this->check();
|
|
|
+ $old_password = Dever::input('old_password');
|
|
|
+ $password = Dever::input('password');
|
|
|
+ if ($old_password == $password) {
|
|
|
+ Dever::alert('旧密码与新密码相同');
|
|
|
+ }
|
|
|
+ $cpassword = Dever::input('cpassword');
|
|
|
+ if ($password != $cpassword) {
|
|
|
+ Dever::alert('新密码与确认密码不同');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Dever::load('passport/user-one', $uid);
|
|
|
+ if ($info) {
|
|
|
+ $update['password'] = sha1($password);
|
|
|
+ $update['where_id'] = $uid;
|
|
|
+ Dever::load('passport/user-update', $update);
|
|
|
+ } else {
|
|
|
+ Dever::alert('更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Dever::load('user/lib/info')->getSign($uid);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+}
|