承接 tinyapps/tinyusermanager 相关项目开发

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

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

tinyapps/tinyusermanager

Composer 安装命令:

composer require tinyapps/tinyusermanager

包简介

Easy-to-use PHP-library for user management

README 文档

README

Easy-to-use PHP-library for user management

Setup

  1. Install with composer: composer require tinyapps/tinyusermanager
  2. Setup database connection For example you can create a db-config.php:
<?php

return [
  'host' => '127.0.0.1',
  'db' => 'your_db',
  'user' => 'db_user',
  'password' => 'db_password'
];

And use the config file for establishing the connection:

$dbConfig = require __DIR__ . '/path-to/db-config.php';

TinyUserManager\Helpers\Database::conn(
  $dbConfig['host'],
  $dbConfig['db'],
  $dbConfig['user'],
  $dbConfig['password'],
  'utf8mb4'
);
  1. Setup the db tables using TinyUserManager\Setup::createTables();
  2. (Optionally) customize the user table by adding additional fields/columns

Code Examples

Please note, that Database::conn() must be called in every script before the usage of the TinyUserManager features that require a database connection. When using sessions, it is also required to have a php session started (session_start()). A documentation will be added soon.

Login

$session = new TinyUserManager\Session();
if ($session->login('john.doe@example.com', 'opensesame')) {
  // login succeded
} else {
  // wrong credentials
}

Check if a user is signed in

if ($session->loggedIn()) {
  // user is logged in
  $user = $session->getUser();
}

Registration

The code snippet below includes a custom field "phone" that has been added to the users table before.

if ($user = TinyUserManager\UserManager::createUser('john.doe@example.com', 'opensesame', ['phone' => '+49 123 45678'])) {
  // User has been created
}

Send the confirmation email

$emailConfig = new TinyUserManager\EmailConfig('no-reply@example.com', 'Example');

TinyUserManager\ConfirmationHandler::sendConfirmationEmail($user, $emailConfig, 'Please confirm your registration', '<p><a href="https://example.com/activate/%uid%/%token%">Activate account</a></p>');

Optionally, if you want to use smtp, you can customize the $emailConfig:

$emailConfig->useSmtp();
$emailConfig->setHost('mail.example.com');
$emailConfig->setUsername('no-reply@example.com');
$emailConfig->setPassword('your_email_password');
$emailConfig->setPort(465);
$emailConfig->setSmtpSecure('ssl');

To activate an account from the activation email:

$user = TinyUserManager\UserManager::getUser($userId);
if (TinyUserManager\ConfirmationHandler::confirmUser($user, $token)) {
  // confirmed
}

Update user details

$user->setField('phone', '+49 123 456789');
TinyUserManager\UserManager::updateUser($user);

Password reset

Send the password reset confirmation email:

TinyUserManager\PasswordResetHandler::sendConfirmationEmail(
	$user,
	$emailConfig,
	$emailSubject,
	'<a href="https://example.com/reset/?uid=%uid%&token=%token%">Reset password</a>',
);

Confirm a password reset token:

$user = TinyUserManager\UserManager::getUser($userId);
if (TinyUserManager\PasswordResetHandler::confirmPasswordForgotToken($user, $token)) {
  // valid
}

Set a new password (confirm the token again before!)

TinyUserManager\PasswordResetHandler::setNewPassword($user, $newPassword);

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固