承接 userapp/widget 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

userapp/widget

Composer 安装命令:

composer require userapp/widget

包简介

PHP user widget for UserApp.

README 文档

README

Wraps the UserApp PHP client into a small and user-friendly API.

Getting started

Finding your App Id

If you don't have a UserApp account, you need to create one.

  • App Id: The App Id identifies your app. After you have logged in, you should see your App Id instantly. If you're having trouble finding it, follow this guide.

Loading the library

UserApp relies on the autoloading features of PHP to load its files when needed. The autoloading complies with the PSR-0 standard which makes it compatible with most of the major frameworks and libraries. Autoloading in your application is handled automatically when managing the dependencies with Composer.

Using Composer? Add this to your composer.json

{
	"require": {
		"userapp/widget": "~0.6.3"
	}
}

Not using Composer? Use the library's own autoloader

require 'autoload.php';

Example

bootstrap.php

<?php

use \UserApp\Widget\User;

// Import composer autoloader
require_once('vendor/autoload.php');

User::setAppId("YOUR APP ID");

must_authenticate.php

<?php

use \UserApp\Widget\User;

require_once('bootstrap.php');

User::onUnauthorized(function ($sender, $call_context, $error){
    header('Location: /login.php');
    die();
});

login.php

<?php

use \UserApp\Widget\User;

require_once('bootstrap.php');

if($_SERVER['REQUEST_METHOD'] === 'POST'){
    $redirect_to = 'login.php?error=INVALID_CREDENTIALS';

    if(User::login($_POST['username'], $_POST['password'])){
        $redirect_to = 'user/profile.php';
    }

    header('Location: /' . $redirect_to);
    die();
}

?>

<form method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
	
	<? if(isset($_GET['error']) && $_GET['error'] == 'INVALID_CREDENTIALS'){ ?>
		* Invalid username or password<br />
	<? } ?>

    <input type="submit" value="Log in" />
</form>

user/profile.php

<?php

use \UserApp\Widget\User;

require_once('../must_authenticate.php');

$user = User::current();

?>

User id: <?= $user->user_id ?><br /><br />
Username: <?= ($user->login ?: '(not specified)') ?><br />
First name: <?= ($user->first_name ?: '(not specified)') ?><br />
Last name: <?= ($user->last_name ?: '(not specified)') ?><br />
Email: <?= ($user->email ?: '(not specified)') ?><br />

<a href="logout.php">Logout</a>

user/logout.php

<?php

use \UserApp\Widget\User;

require_once('../must_authenticate.php');

$user = User::current();
$user->logout();

header('Location: ../login.php');

API

Logging in

bool User::login($username, $password)

Logging in with a token

bool User::loginWithToken($token)

Signing up a new user

bool User::signup($username, $password, $email = null, $first_name = null, $last_name = null, $auto_login = true)

Checking if a user is authenticated

bool User::authenticated()

Getting the currently authenticated user

User User::current()

Example

$user = User::current();
$user->logout();

Reading a property of a user

$user->user_id

$user->properties->age->value

Supported properties

  • string user_id
  • string first_name
  • string last_name
  • string email
  • string login
  • object properties
  • object features
  • object permissions
  • array locks
  • string ip_address
  • int last_login_at
  • int updated_at
  • int created_at

Checking whether a user has a permission

bool $user->hasPermission($permission_name)

Checking whether a user has a feature

bool $user->hasFeature($feature_name)

Saving changes on a user

void $user->save()

Example

$user->first_name = 'John';
$user->last_name = 'Johnsson';
$user->properties->my_own_property = 'some value';
$user->save();

Logging out a user

void $user->logout()

Callback when unauthorized

void onUnauthorized(closure($sender, $call_context, $error))

Example

User::onUnauthorized(function($sender, $call_context, $error){
    header('Location: /login.php');
    die();
});

Licence

MIT

统计信息

  • 总下载量: 795
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 4
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固