public function loginAction() { session_start(); if (IS_POST) { $username = I('post.username'); $password = I('post.password'); if (empty($username) || empty($password)) { $this->error('请输入用户名及密码'); } $acl = new Acl(); $user = $acl->getUser($username, true); if (!empty($user)) { $pwd = Utility::encodePassword($password, $user['salt']); if ($pwd != $user['password']) { $this->error('您输入的密码错误'); } if ($user['status'] == Acl::STATUS_DISABLED) { $this->error('您的账号已经被禁用, 请联系系统管理员'); } $user = coll_elements(array('uid', 'username', 'role'), $user); session('user', $user); $forward = I('get.forward'); if (empty($forward)) { $forward = U('bench/welcome/index'); } else { $forward = base64_decode($forward); } $this->success('成功登陆', $forward); } else { $this->error('您输入的用户名或密码错误'); } exit; } $this->display('Wander/login'); }
public function run(&$params) { $module = MODULE_NAME; $controller = CONTROLLER_NAME; $action = ACTION_NAME; if (in_array($module, array('Wander', 'Api'))) { return; } session_start(); $user = session('user'); if (!empty($user)) { $session = array(); $session['USER'] = array_change_key_case($user, CASE_UPPER); $acl = new Acl(); $roles = $acl->getRoles(); $roles = coll_key($roles, 'id'); $role = $roles[$user['role']]; if (empty($role)) { $role = $roles[0]; } $role = coll_elements(array('id', 'title'), $role); $session['ROLE'] = array_change_key_case($role, CASE_UPPER); $session['ACL'] = array(); C('SESSION', $session); } //无用户身份, 只能访问Wander if ((empty($session) || empty($session['USER'])) && !in_array($module, array('Wander', 'Api'))) { redirect(U('/wander/account/login?forward=' . base64_encode($_SERVER['REQUEST_URI']))); exit; } }
public function weixinModify() { $id = intval(I('get.id')); if (empty($id)) { $this->error('访问错误'); } $b = new Bridge($this->addon); $platform = $b->getOne($id); if (empty($platform)) { $this->error('访问错误'); } if (IS_POST) { $rec = coll_elements(array('title', 'url', 'token', 'remark'), I('post.')); if (empty($rec['title']) || empty($rec['url']) || empty($rec['token'])) { $this->error('请填写完整后保存'); } $rec = $b->table('__BR_BRIDGES__')->data($rec)->where("`id`='{$id}'")->save(); if (!empty($rec)) { $this->success('保存接入平台成功', $this->U('connect/weixin')); exit; } else { $this->error('保存失败, 可能是因为这个平台已经接入过, 请检查 URL'); } } $this->assign('entity', $platform); $this->display('weixin-form'); }
public function rolesAction() { $roles = $this->acl->getRoles(true); $roles = coll_key($roles, 'id'); $id = I('get.id'); if (!empty($id)) { $id = intval($id); if ($id > 0) { $role = $roles[$id]; $this->assign('entity', $role); if (!empty($role)) { if (I('get.do') == 'delete') { if ($this->acl->removeRole($id)) { $this->success('成功删除用户组', U('control/acl/roles')); exit; } else { $this->error('操作失败, 请稍后重试'); } } } } if (IS_POST) { $input = coll_elements(array('title', 'status', 'remark'), I('post.')); $input['title'] = trim($input['title']); if (empty($input['title'])) { $this->error('请输入用户组名称'); } $input['status'] = $input['status'] == '-1' ? '-1' : '0'; $input['parent'] = '0'; if (!empty($role)) { //编辑组 $ret = $this->acl->table('__USR_ROLES__')->data($input)->where("`id`={$id}")->save(); if (empty($ret)) { $this->error('保存用户组失败, 请稍后重试'); } else { $this->success('成功保存用户组', U('control/acl/roles')); exit; } } else { //新增组 $ret = $this->acl->table('__USR_ROLES__')->data($input)->add(); if (empty($ret)) { $this->error('保存新增用户组失败, 请稍后重试'); } else { $this->success('成功新增用户组', U('control/acl/roles')); exit; } } } } $this->assign('roles', $roles); $this->display(); }
public function modifyUser($uid, $user) { $uid = intval($uid); $input = coll_elements(array('password', 'role', 'status'), $user); $user = $this->getUser($uid); $input['password'] = Utility::encodePassword($input['password'], $user['salt']); $ret = $this->table('__USR_USERS__')->data($input)->where("`uid`={$uid}")->save(); if ($ret !== false) { return true; } return error(-2, '保存用户数据失败, 请稍后重试'); }
public function closeAction() { Site::loadSettings(); $settings = C('SITE'); if (IS_POST) { $close = coll_elements(array('close', 'tips'), I('post.')); $settings[Site::OPT_CLOSE] = intval($close['close']); $settings[Site::OPT_CLOSETIPS] = $close['tips']; Site::saveSettings($settings); $this->success('操作成功'); exit; } $entity = array(); $entity['close'] = $settings[Site::OPT_CLOSE]; $entity['tips'] = $settings[Site::OPT_CLOSETIPS]; $this->assign('entity', $entity); C('FRAME_CURRENT', U('control/site/common')); $this->display(); }
public function saveLog($order) { if (empty($order['uid']) || empty($order['title']) || empty($order['fee']) || empty($order['tid']) || empty($order['addon'])) { return error(-1, 'error arguments'); } $rec = coll_elements(array('uid', 'tid', 'fee', 'title', 'addon'), $order); $pars = array(); $pars[':tid'] = $rec['tid']; $pars[':addon'] = $rec['addon']; $log = $this->table('__CORE_PAYLOGS__')->where('`tid`=:tid AND `addon`=:addon')->bind($pars)->find(); if (!empty($log)) { if ($log['status'] == self::STATUS_DISBURSED) { return error(-2, '这个订单已经支付过了'); } $this->table('__CORE_PAYLOGS__')->data($rec)->where("`plid`='{$log['plid']}'")->save(); } else { $rec['type'] = ''; $rec['status'] = self::STATUS_CREATED; $rec['extras'] = ''; $ret = $this->table('__CORE_PAYLOGS__')->add($rec); if (empty($ret)) { return error(-3, '创建支付订单失败'); } $log = $rec; $log['plid'] = $this->getLastInsID(); } return $log['plid']; }
/** * 登记当前消息中的用户资料, 在派生类中实现时, 应至少传递 openid, unionid, subscribe, subscribetime, unsubscribetime, tag * @param $message * @return boolean */ public function booking($message) { $account = $this->getAccount(); if (!empty($account) && !empty($message)) { $fan = coll_elements(array('openid', 'unionid', 'subscribe', 'subscribetime', 'unsubscribetime', 'tag'), $message); $fan['platformid'] = $account['id']; $condition = '`platformid`=:platformid AND `openid`=:openid'; $pars = array(); $pars[':platformid'] = $fan['platformid']; $pars[':openid'] = $fan['openid']; $m = new Model(); $fanid = $m->table('__MMB_MAPPING_FANS__')->where($condition)->bind($pars)->getField('`fanid`'); if (empty($fanid)) { $fan['uid'] = 0; //判断用户中心策略 $fan['salt'] = util_random(8); if (empty($fan['subscribetime'])) { $fan['subscribetime'] = TIMESTAMP; } $m->table('__MMB_MAPPING_FANS__')->data($fan)->add(); } else { if (empty($fan['subscribetime'])) { unset($fan['subscribetime']); } if (empty($fan['unsubscribetime'])) { unset($fan['unsubscribetime']); } $m->table('__MMB_MAPPING_FANS__')->data($fan)->where("`fanid`='{$fanid}'")->save(); } } }
private function validateForm($modify = false) { $input = coll_elements(array('username', 'password', 'role', 'status'), I('post.')); $input['username'] = trim($input['username']); if (empty($modify)) { if (empty($input['username']) || empty($input['password'])) { $this->error('请输入用户名及登陆密码'); } } if ($input['role'] === false) { $this->error('必须指定用户组'); } $roles = coll_key($this->roles, 'id'); if (empty($roles[$input['role']])) { $input['role'] = '0'; } $input['status'] = $input['status'] == '-1' ? '-1' : '0'; return $input; }
public function create($member, $fan = null) { if (!preg_match('/^1\\d{10}$/', $member['mobile'])) { return error(-1, '你输入的手机号格式不正确'); } $condition = '`mobile`=:mobile'; $pars = array(); $pars[':mobile'] = $member['mobile']; $exist = $this->table('__MMB_MEMBERS__')->where($condition)->bind($pars)->find(); if (!empty($exist)) { return error(-2, '你输入的手机号已经注册过, 请直接登陆或者更换后重试'); } $rec = coll_elements(array('mobile', 'password'), $member, ''); $rec['salt'] = util_random(8); $rec['password'] = Utility::encodePassword($rec['password'], $rec['salt']); $condition = '`isdefault`=1'; $pars = array(); $group = $this->table('__MMB_GROUPS__')->where($condition)->bind($pars)->find(); $rec['groupid'] = $group['id']; $rec['createtime'] = TIMESTAMP; $rec['joinfrom'] = $member['from']; if (empty($rec['joinfrom'])) { $rec['joinfrom'] = ''; } $ret = $this->table('__MMB_MEMBERS__')->data($rec)->add(); if (empty($ret)) { return error(-2, '系统错误, 创建会员失败, 请稍后重试'); } $uid = $this->getLastInsID(); $this->table('__MMB_PROFILES__')->data(array('uid' => $uid))->add(); if (!empty($fan) && empty($fan['uid'])) { if ($rec['joinfrom'] == 'weixin') { $record = array(); $record['uid'] = $uid; $this->table('__MMB_MAPPING_FANS__')->data($record)->where("`fanid`='{$fan['fanid']}' OR `unionid`='{$fan['unionid']}'")->save(); } } return $uid; }
public function groupsAction() { $m = new Member(); $groups = $m->getGroups(); $groups = coll_key($groups, 'id'); if (IS_POST && I('post.batch')) { $def = I('post.default'); if (!empty($groups[$def])) { $m->table('__MMB_GROUPS__')->data(array('isdefault' => '0'))->where("`id`!={$def}")->save(); $m->table('__MMB_GROUPS__')->data(array('isdefault' => '1'))->where("`id`={$def}")->save(); } $select = I('post.orderlist'); if (!empty($select)) { foreach ($select as $k => $v) { if (!empty($groups[$k])) { $v = util_limit($v, 0, 255); $m->table('__MMB_GROUPS__')->data(array('orderlist' => $v))->where("`id`={$k}")->save(); } } } $this->success('操作成功'); exit; } $id = I('get.id'); if (!empty($id)) { $id = intval($id); if ($id > 0) { $group = $groups[$id]; $this->assign('entity', $group); if (!empty($group)) { if (I('get.do') == 'delete') { if ($m->removeGroup($id)) { $this->success('成功删除会员组', U('control/member/groups')); exit; } else { $this->error('操作失败, 请稍后重试'); } } } } if (IS_POST) { $input = coll_elements(array('title', 'remark'), I('post.')); $input['title'] = trim($input['title']); if (empty($input['title'])) { $this->error('请输入会员组名称'); } if (!empty($group)) { //编辑组 $ret = $m->table('__MMB_GROUPS__')->data($input)->where("`id`={$id}")->save(); if (empty($ret)) { $this->error('保存会员组失败, 请稍后重试'); } else { $this->success('成功保存会员组', U('control/member/groups')); exit; } } else { //新增组 $input['orderlist'] = '0'; $input['isdefault'] = '0'; $ret = $m->table('__MMB_GROUPS__')->data($input)->add(); if (empty($ret)) { $this->error('保存新增会员组组失败, 请稍后重试'); } else { $this->success('成功新增会员组', U('control/member/groups')); exit; } } } } $this->assign('groups', $groups); C('FRAME_CURRENT', U('control/member/groups')); $this->display(); }
private function doInstall($addon) { $define = Addon::getAddon($addon, true); if (is_error($define)) { $this->error($define['message']); } else { $rec = coll_elements(array('name', 'type', 'title', 'version', 'description', 'author', 'url'), $define, ''); $m = new Model(); $ret = $m->table('__EX_ADDONS__')->data($rec)->add(); if (!empty($ret)) { Addon::autoload(); $class = "Addon\\{$addon}\\Api\\Application"; if (class_exists($class)) { $instance = new $class(); if (!empty($instance)) { $instance->addon = new Addon($addon); if (method_exists($instance, 'install')) { $ret = $instance->install(); } } } if (is_error($ret)) { $this->error('扩展未能安装成功, 请完全卸载后重试, 或者联系扩展开发商. 扩展提供的详细错误信息为: ' . $ret['message']); } else { $this->success('扩展安装成功'); } } exit; } }
public static function saveSettings($settings) { $keys = self::getOptions(); $settings = coll_elements($keys, $settings); return Utility::saveSettings('SITE', $settings); }