当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthUser::meta方法代码示例

本文整理汇总了PHP中AuthUser::meta方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthUser::meta方法的具体用法?PHP AuthUser::meta怎么用?PHP AuthUser::meta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AuthUser的用法示例。


在下文中一共展示了AuthUser::meta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: forgot

	function forgot () {
		
		// Load Auth app
		$auth_app = Frix::app('auth');
		
		// Already authorized?
		if ($auth_app->get_user()) {
			// Go to the admin home
			redir(url(self::$root));
		}
		
		// Load AuthUser model
		$auth_app->load_model('AuthUser');
		// Get model meta
		$meta = AuthUser::meta();
		
		$f = new Form;
		$f->add_fields(array(
			'email' => new CharField('E-mail', array('length' => 100)),
		));
		
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			
			// Get form data
			$f->input($_POST);
			
			$email = $f->get_email();
			
			// Check for a valid e-mail address.
			if (!validate_email($email)) {
				self::$context['msg'] = sprintf('Invalid e-mail address "%s"!', $email);
				self::$context['msg_type'] = 'err';
			}
			else {
				// Get user by e-mail address
				$user = $meta->one(array('email' => $email));
				
				if ($user) {
					
					// Create a new password
					$pass = make_pass();
					
					$msg =
						'Your new passord is:' . "\n" .
						$pass . "\n\n" .
						'You can log in using your username:' . "\n" .
						$user->username
					;
					
					// Send the password to the user
					$ok = send_mail('New password', $msg, Frix::app('settings')->get('contact_email'), $user->email);
					
					// Error sending the msg?
					if (!$ok) {
						self::$context['msg'] =
							'Couldn\'t send msg.<br />' .
							'Password not changed.'
						;
						self::$context['msg_type'] = 'err';
					}
					// Message sucessfully sent?
					else {
						// Change user password and save
						$user->set_password($pass);
						$user->save();
						// Redirect with a success msg
						redir('./?sent=1');
					}
					
				}
				else {
					self::$context['msg'] = sprintf('E-mail address "%s" not found!', $email);
					self::$context['msg_type'] = 'err';
				}
			}
			
		}
		else {
			if ($_GET['sent']) {
				self::$context['msg'] =
					'The new password was sent!<br />'.
					'Please check your inbox.'
				;
				self::$context['msg_type'] = 'ok';
			}
			else {
				self::$context['msg'] = 'Type your e-mail to get a new password.';
			}
		}
		
		self::$context['form'] = $f;
		
		$t = new Template('frix/admin/forgot');
		echo $t->render(self::$context);
		
	}
开发者ID:ricobl,项目名称:frix,代码行数:96,代码来源:views.php


注:本文中的AuthUser::meta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。