/** * Saves user submissions for Independent Sponsor requests. */ public function postRequest() { //Grab input $address1 = Input::get('address1'); $address2 = Input::get('address2'); $city = Input::get('city'); $state = Input::get('state'); $postal = Input::get('postal'); $phone = Input::get('phone'); $all_input = Input::all(); //Validate input $rules = array('address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal' => 'required', 'phone' => 'required'); $validation = Validator::make($all_input, $rules); if ($validation->fails()) { return Redirect::to('/documents/sponsor/request')->withInput()->withErrors($validation); } //Add new user information to their record $user = Auth::user(); $user->address1 = $address1; $user->address2 = $address2; $user->city = $city; $user->state = $state; $user->postal_code = $postal; $user->phone = $phone; $user->save(); //Add UserMeta request $request = new UserMeta(); $request->meta_key = UserMeta::TYPE_INDEPENDENT_SPONSOR; $request->meta_value = 0; $request->user_id = $user->id; $request->save(); return Redirect::to('/user/edit/' . $user->id)->with('message', 'Your request has been received.'); }
/** * Saves user submissions for Independent Sponsor requests. */ public function putRequest() { //Validate input $rules = array('address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'phone' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { return Response::json($this->growlMessage($validation->messages()->all(), 'error'), 400); } //Add new user information to their record $user = Auth::user(); $user->address1 = Input::get('address1'); $user->address2 = Input::get('address2'); $user->city = Input::get('city'); $user->state = Input::get('state'); $user->postal_code = Input::get('postal_code'); $user->phone = Input::get('phone'); $user->save(); if (!$user->getSponsorStatus()) { //Add UserMeta request $request = new UserMeta(); $request->meta_key = UserMeta::TYPE_INDEPENDENT_SPONSOR; $request->meta_value = 0; $request->user_id = $user->id; $request->save(); } return Response::json(); }
public function index($slug = null) { //No document requested, list documents if (null == $slug) { $docs = Doc::all(); $data = array('docs' => $docs, 'page_id' => 'docs', 'page_title' => 'All Documents'); return View::make('doc.index', $data); } try { //Retrieve requested document $doc = Doc::where('slug', $slug)->with('statuses')->with('userSponsor')->with('groupSponsor')->with('categories')->with('dates')->first(); if (!isset($doc)) { App::abort('404'); } $showAnnotationThanks = false; if (Auth::check()) { $userId = Auth::user()->id; $userMeta = UserMeta::where('user_id', '=', $userId)->where('meta_key', '=', UserMeta::TYPE_SEEN_ANNOTATION_THANKS)->take(1)->first(); if ($userMeta instanceof UserMeta) { $showAnnotationThanks = !$userMeta->meta_value; } else { $showAnnotationThanks = true; } } //Set data array $data = array('doc' => $doc, 'page_id' => strtolower(str_replace(' ', '-', $doc->title)), 'page_title' => $doc->title, 'showAnnotationThanks' => $showAnnotationThanks); //Render view and return return View::make('doc.reader.index', $data); } catch (Exception $e) { return Redirect::to('/')->with('error', $e->getMessage()); } App::abort('404'); }
public static function postProfile() { if (current_user_can('profile')) { $user_id = get_current_user_id(); $usermeta = \UserMeta::where('user_id', $user_id)->first(); $usermeta->updateMe(\Input::all()); self::profile(); } }
/** * Verification request view */ public function getVerifications() { $user = Auth::user(); if (!$user->can('admin_verify_users')) { return Redirect::to('/dashboard')->with('message', "You do not have permission"); } $requests = UserMeta::where('meta_key', 'verify')->with('user')->get(); $data = array('page_id' => 'verify_users', 'page_title' => 'Verify Users', 'requests' => $requests); return View::make('dashboard.verify-account', $data); }
public function seenAnnotationThanksModal() { if (!Auth::check()) { throw new Exception("Unauthorized"); } $userId = Auth::user()->id; $userMeta = UserMeta::firstOrNew(array('user_id' => $userId, 'meta_key' => UserMeta::TYPE_SEEN_ANNOTATION_THANKS)); $userMeta->meta_value = true; $userMeta->save(); }
public function postVerify() { $this->beforeFilter('admin'); $request = Input::get('request'); $status = Input::get('status'); $accepted = array('pending', 'verified', 'denied'); if (!in_array($status, $accepted)) { throw new Exception('Invalid value for verify request: ' . $status); } $meta = UserMeta::find($request['id']); $meta->meta_value = $status; $ret = $meta->save(); return Response::json($ret); }
/** * sanitize the params .(if there was a problem in a occurred an exception will throw ) * * @param array $wpNeeds * @return mixed returns user or errors */ public function register(array $wpNeeds) { $user = new \stdClass(); $user->user = null; $user->error = false; if ($error = $this->sanitize($wpNeeds) === true) { /** * making object from arrays for easier writability */ $wpNeedsObj = $this->formatter->arrayToStdClass($wpNeeds); /** * doing the registration */ $id = $this->insertUser($wpNeeds); /** * fetching registered user */ if (is_integer($id)) { $user = new \WP_User($id); $user->add_cap("profile"); $usermeta = new \UserMeta(); $usermeta->user_id = $id; $usermeta->save(); $usermeta = \UserMeta::where('user_id', $id)->first(); $user = \WpUser::where("ID", $id)->first(); $user->meta_id = $usermeta->id; $user->save(); $user->user = $this->db->getRegisteredUser($id); unset($user->error); /** * user structure is * $user->user * $user->email */ return $user; } return $user; } $user->error = $error; return $user; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param UserMeta $value A UserMeta object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(UserMeta $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * getValidSponsors. * * @todo I'm not sure what exactly this does at first glance */ public function getValidSponsors() { $collection = new Collection(); $groups = GroupMember::where('user_id', '=', $this->id)->whereIn('role', array(Group::ROLE_EDITOR, Group::ROLE_OWNER))->get(); foreach ($groups as $groupMember) { $collection->add($groupMember->group()->first()); } $users = UserMeta::where('user_id', '=', $this->id)->where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', '1')->get(); foreach ($users as $userMeta) { $collection->add($userMeta->user()->first()); } return $collection; }
/** * putEdit. * * User's put request to update their profile * * @param User $user * * @return Illuminate\Http\RedirectResponse */ public function putEdit(User $user) { if (!Auth::check()) { return Response::json($this->growlMessage('Please log in to edit user profile', 'error'), 401); } elseif (Auth::user()->id != $user->id) { return Response::json($this->growlMessage('You do not have access to that profile.', 'error'), 403); } elseif ($user == null) { return Response::error('404'); } if (strlen(Input::get('password')) > 0) { $user->password = Input::get('password'); } $verify = Input::get('verify_request'); $user->email = Input::get('email'); $user->fname = Input::get('fname'); $user->lname = Input::get('lname'); $user->url = Input::get('url'); $user->phone = Input::get('phone'); $user->verify = $verify; // Don't allow oauth logins to update the user's data anymore, // since they've set values within Madison. $user->oauth_update = false; if (!$user->save()) { $messages = $user->getErrors()->toArray(); $messageArray = []; foreach ($messages as $key => $value) { //If an array of messages have been passed, push each one onto messageArray if (is_array($value)) { Log::info($value); foreach ($value as $message) { array_push($messageArray, $message); } } else { //Otherwise just push the message value array_push($messageArray, $value); } } return Response::json($this->growlMessage($messageArray, 'error'), 400); } if (isset($verify)) { $meta = new UserMeta(); $meta->meta_key = 'verify'; $meta->meta_value = 'pending'; $meta->user_id = $user->id; $meta->save(); Event::fire(MadisonEvent::VERIFY_REQUEST_USER, $user); return Response::json($this->growlMessage(['Your profile has been updated', 'Your verified status has been requested.'], 'success')); } return Response::json($this->growlMessage('Your profile has been updated.', 'success')); }
/** * * 列举共享信息 */ public function handlerListDetails() { $this->_slaves = array(); $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'user_id' => $this->_userId, 'is_deleted' => 0)); if (is_null($this->_file)) { throw new ApiException('Not Found'); } if ($this->_file['file_type'] != 2) { throw new ApiException('Not Found'); } $meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_file['file_path'], 'meta_key' => self::SHARED_META_FLAG)); if (!$meta) { throw new ApiException('Not Found'); } $meta_value = unserialize($meta['meta_value']); if ($meta_value['master'] != $this->_userId) { throw new ApiException('Not Found'); } $slaves = $meta_value['slaves']; $send = $meta_value['send_msg']; foreach ($slaves as $key => $value) { $user = User::model()->findByPk($key); if (!$user) { continue; } $mate = UserMeta::model()->findByAttributes(array("user_id" => $user->id, "meta_key" => "nick")); if ($mate) { $value = $mate->meta_value; if (!empty($value) && strlen(trim($value)) > 0) { $nick = $value; } } else { $nick = $user['user_name']; } $shared_file = UserFile::model()->findByAttributes(array('user_id' => $key, 'file_path' => $value, 'is_deleted' => 0)); $path = $this->_file['file_path']; $permission = Yii::app()->privilege->checkPrivilegeUser($key, $path); array_push($this->_slaves, array('user_id' => $key, 'user_name' => $user['user_name'], 'nick' => $nick, 'type' => $shared_file['file_type'], 'permission' => $permission, 'send' => $send)); } }
/** * * 列举共享信息 * * @since 1.1.0 */ public function handlerListDetails() { $this->_slaves = array(); $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'is_deleted' => 0)); if (is_null($this->_file)) { throw new ApiException('Not Found'); } //判断此用户是否有 分配 权限 $file_path = $this->_file["file_path"]; $hasPermissionAllot = Yii::app()->privilege->hasPermission($file_path, MPrivilege::PERMISSION_GRANT); if (!$hasPermissionAllot) { $this->result["msg"] = Yii::t('front_common', 'Can not grant permission'); throw new ApiException('Can not grant permission'); } //获取此文件的拥有者 $master = CUtils::getUserFromPath($file_path); $privileges = MUserPrivilege::model()->findAll('file_path=:file_path', array(':file_path' => $this->_file['file_path'])); foreach ($privileges as $pri) { //文件属于拥有者则不能进行权限分配 if ($pri["user_id"] == $master) { continue; } //文件属于自己是不进行权限分配 $currentUser = MUserManager::getInstance()->getCurrentUser(); if ($pri["user_id"] == $currentUser["id"]) { continue; } $user = User::model()->findByPk($pri["user_id"]); if (!$user) { continue; } $mate = UserMeta::model()->findByAttributes(array("user_id" => $user->id, "meta_key" => "nick")); if ($mate) { $nick = $mate->meta_value; } else { $nick = $user['user_name']; } //没有设置分配权限则默认为不分配 $permission = unserialize($pri["permission"]); if (!isset($permission[MPrivilege::PERMISSION_GRANT])) { $permission[MPrivilege::PERMISSION_GRANT] = 0; } array_push($this->_slaves, array('user_id' => $pri["user_id"], 'user_name' => $user['user_name'], 'nick' => $nick, 'permission' => $permission)); } }
/** * * 赋予用户角色 */ public function changeRole($userIds, $isAdmin) { if ($userIds != '' && strlen($userIds) > 0) { $idsArray = explode(",", $userIds); //查出admin 用户信息 $userInfo = $this->find('user_name=:user_name', array(':user_name' => 'admin')); foreach ($idsArray as $index => $userId) { //如果是amdin账号id则不修改角色信息 if ($userInfo['id'] == $userId) { continue; } $userMeta = new UserMeta(); $item = $userMeta->find("meta_key='is_admin' and user_id=" . $userId); if (isset($item)) { $userMeta = $item; } else { $userMeta["meta_key"] = "is_admin"; $userMeta["user_id"] = $userId; $userMeta["created_at"] = date("Y-m-d H:i:s"); $userMeta["updated_at"] = date("Y-m-d H:i:s"); } $userMeta["meta_value"] = $isAdmin ? "1" : "0"; $userMeta->save(); } } }
/** * * 执行搜索操作 */ private function handlerSeach() { $params = array(); $params[':user_name'] = "%" . $this->search_key . "%"; $params[':meta_value'] = "%" . $this->search_key . "%"; // // 联合查询 // $conditions = User::model()->tableName() . ' as u left outer join '; $conditions .= UserMeta::model()->tableName(); $conditions .= ' as m on m.user_id = u.id and m.meta_key="nick" '; $conditions .= ' WHERE user_name like :user_name or meta_value like :meta_value'; $count_sql = 'SELECT count(*) as count FROM ' . $conditions; $this->total = User::model()->countBySql($count_sql, $params); // 创建sql $query = 'SELECT u.*,m.meta_value as nick FROM ' . $conditions; $query .= ' limit :offset, :limit'; $command = Yii::app()->db->createCommand($query); $command->bindParam(':user_name', $params[':user_name']); $command->bindParam(':meta_value', $params[':meta_value']); $command->bindParam(':limit', $this->limit); $command->bindParam(':offset', $this->offset); $userList = $command->queryAll(); $users = array(); if ($this->callback) { $users = call_user_func($this->callback, $userList, $this->total); } else { foreach ($userList as $user) { $user_name = trim($user['nick']); $user_name = empty($user_name) ? $user['user_name'] : $user_name; $users[$user['id']] = array("id" => $user['id'], "user_name" => $user_name); } $users = CJSON::encode($this->_getHashByList($users)); } return $users; }
/** * Update the meta data of the user. * @param User $user - the user who wants to update meta data * @param String $metaKey - the key of the meta * @param String $metaValue - the value of the meta */ private function updateUserMeta($user, $metaKey, $metaValue) { $userMeta = UserMeta::findFirst(array('conditions' => 'uid = ?1 AND meta_key = ?2', 'bind' => array(1 => $user->getUid(), 2 => $metaKey))); if ($userMeta == NULL) { if (empty($metaValue)) { return; } $userMeta = new UserMeta(); $userMeta->setUser($user); $userMeta->setMetaKey($metaKey); $userMeta->setMetaValue($metaValue); $userMeta->create(); } else { $userMeta->setMetaValue($metaValue); $userMeta->update(); } }
/** * putEdit * * User's put request to update their profile * * @param User $user * @return Illuminate\Http\RedirectResponse */ public function putEdit(User $user) { if (!Auth::check()) { return Redirect::to('user/login')->with('error', 'Please log in to edit user profile'); } else { if (Auth::user()->id != $user->id) { return Redirect::back()->with('error', 'You do not have access to that profile.'); } else { if ($user == null) { return Response::error('404'); } } } if (strlen(Input::get('password_1')) > 0 || strlen(Input::get('password_2')) > 0) { if (Input::get('password_1') !== Input::get('password_2')) { return Redirect::to('user/edit/' . $user->id)->with('error', 'The passwords you\'ve entered do not match.'); } else { $password = Input::get('password_1'); } } $verify = Input::get('verify'); $user->email = Input::get('email'); $user->fname = Input::get('fname'); $user->lname = Input::get('lname'); $user->url = Input::get('url'); $user->phone = Input::get('phone'); $user->verify = $verify; // Don't allow oauth logins to update the user's data anymore, // since they've set values within Madison. $user->oauth_update = false; if (!$user->save()) { return Redirect::to('user/edit/' . $user->id)->withInput()->withErrors($user->getErrors()); } if (isset($verify)) { $meta = new UserMeta(); $meta->meta_key = 'verify'; $meta->meta_value = 'pending'; $meta->user_id = $user->id; $meta->save(); Event::fire(MadisonEvent::VERIFY_REQUEST_USER, $user); return Redirect::back()->with('success_message', 'Your profile has been updated')->with('message', 'Your verified status has been requested.'); } return Redirect::back()->with('success_message', 'Your profile has been updated.'); }
/** * 添加用户meta信息 * @param $metas 用户的一些扩展信息 * @param $user 用户名、用户状态及uuid * */ public function create($user, $metas) { //存储用户扩展信息 if (array_key_exists('extend', $metas) && !empty($metas['extend'])) { foreach ($metas['extend'] as $key => $value) { if ($value === null) { continue; } $userMeta = UserMeta::model()->find("user_id=:user_id and meta_key=:key", array(":user_id" => $user['id'], ':key' => $key)); if (!empty($userMeta)) { if ($userMeta['meta_value'] != $value) { $userMeta['meta_value'] = $value; $userMeta->save(); } } else { $userMeta = new UserMeta(); $userMeta["user_id"] = $user["id"]; $userMeta["meta_key"] = $key; $userMeta["meta_value"] = $value; $userMeta->save(); } } } }
/** * 把系统中的中文用户名转化为拼音 */ public function updateAllUserNamePinyin() { $criteria = new CDbCriteria(); $criteria->order = "-id"; $items = User::model()->findAll($criteria); foreach ($items as $item) { if (empty($item->user_name_pinyin)) { //把登陆名转化为拼音 $name = $item->user_name; //把昵称转化为拼音 $nick = ""; $criteria = new CDbCriteria(); $criteria->condition = "user_id=:user_id and meta_key='nick'"; $criteria->params = array(":user_id" => $item->id); $meta = UserMeta::model()->find($criteria); if (!empty($meta)) { $nick = $meta->meta_value; } $item->user_name_pinyin = $this->getPinYinByName($name, $nick); $item->save(); } } }
/** * Get user by Facebook id. * * @param string $token * @return \FIIP\Users\User|null */ public function getByFacebook($id) { $meta = UserMeta::where('key', 'facebook')->where('value', $id)->first(); return $meta ? $meta->user : null; }
public static function getAllValidSponsors() { $userMeta = UserMeta::where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', 1)->get(); $groups = Group::where('status', '=', Group::STATUS_ACTIVE)->get(); $results = new Collection(); $userIds = array(); foreach ($userMeta as $m) { $userIds[] = $m->user_id; } if (!empty($userIds)) { $users = User::whereIn('id', $userIds)->get(); foreach ($users as $user) { $row = array('display_name' => "{$user->fname} {$user->lname}", 'sponsor_type' => 'individual', 'id' => $user->id); $results->add($row); } } foreach ($groups as $group) { $row = array('display_name' => $group->display_name, 'sponsor_type' => 'group', 'id' => $group->id); $results->add($row); } return $results; }