User Library



( ZN >= 1.0.0 )

The class for which a number of operations have been performed for users or members. There are functions such as new membership, introduction to site, activation, use of member information.

 

# Configuration


Since the User library works with the database, the relevant columns of the relevant database table must be reported to the library. The settings for this library are in the following files.

File: ( ZN FE ) Config / IndividualStructures.php
File: ( ZN OE ) Config / Authentication.php
User
String $ encode = 'super' This setting specifies which algorithm the users will use to encrypt their passwords during registration. The super algorithm is pre-defined . If you want md5 instead, You can also choose encryption algorithms such as sha1 . The recommended algorithm is the super algorithm. Because this algorithm differs according to the key set for the project.
Array $ matching The user library needs table and column information to hold information about the user in order to perform user transactions. This section tells you which tables and columns the User :: library will use for the specified configurations.
String $ Table The user action specifies which table to use.
Array $ columns The User :: library needs the column names of some user tables in order to be able to perform operations in the background. This is not to create the columns for the user table, but to match those required for this configuration from the columns in the existing user table.
String $ Username The name of the column in which username information will be stored is specified here. compulsory
String $ password The name of the column where user password information will be stored is specified here. compulsory
String $ email The name of the column in which user email information will be stored is specified here.
String $ Active The name of the column in which the information about whether or not the users are online is held is specified here.
String $ banned The name of the column where the information about whether or not users are banished is specified here.
String $ Activation In order to activate after the user registration, the name of the column where the user activates or not is kept here.
String $ Verification For the password forgotten application, the name of the column where the e-mail belongs to the person performing the transaction is stored here.
String $ Otherlog's If the user wishes to be able to log in using other columns other than the username column, the name of the column to log in with which column other than the username is entered here.
Array $ joining If the user's information is designed to hold more than one table, and if it is desired to be linked to these tables, it is used to establish relationships with the other tables.
String $ columna The column information to be associated with other tables belonging to the user name table specified in the matching: table key is specified.
Array $ tables

The other table and column names to be related are lined up as key value pairs.

Array $ emailsenderınfo The sender name and e-mail address are pre-defined when using e-mails such as activation, verification in user operations.
String $ name Predefined sender name.
String $ mail Predefined sender email address.

 

# Methods


Bool register ( Array $ data , Mixed $ autoLogin = false , String $ return Link = NULL )
Bool login ( String $ un , String $ pw , Mixed $ rememberMe = false )
Bool isLogin ( Void )
Object data ( String $ tbl = NULL )
void logout ( String $ redirectUrl = NULL , Int $ time = 0 )
Bool update ( String $ old , String $ pass , String $ passAgain = NULL , Array $ data = [] )
Bool forgotPassword ( String $ email = NULL , String $ return LinkPath = NULL )
void sendEmailAll ( String $ subject , String $ message )
Bool activationComplete ( Void )
Bool resendActivationEmail ( String $ username , String $ return Link , String $ email = NULL )
Int count ( Void )
Int activeCount ( Void )
Int bannedCount ( Void )
String success ( Void )
String error ( Void )
this autoLogin ( Mixed $ autoLogin = true )
this return Link ( String $ return Link )
this oldPassword ( String $ oldPassword )
this newPassword ( String $ newPassword )
this passwordAgain ( String $ passwordAgain )
this column ( String $ column , Scalar $ value )
this username ( String $ username )
this password ( String $ password )
this remember ( Bool $ remember = true )
this email ( String $ email )
this attachment ( String $ file , String $ disposition = NULL , String $ newName = NULL )

 

# Register ( ZN >= 1.0.0 )


The user information is stored in the configuration file 'Table'setting to the table specified. The first parameter of the register method is specified in the type of the array to be added to the corresponding table.

Parameters

Array $ data User information to record.
Mixed $ autoLogin = false Do you log in automatically after registration? Link may also contain information.
String $ return Link = NULL Activation return link.
return Bool

Optional Methods

this column ( String $ column , String $ data ) It can be used instead of parameter 1 of the register () method .
this autoLogin ( Mixed $ autoLogin ) It can be used in place of parameter 2 of the register () method .
this return Link ( String $ return Link ) It can be used in place of parameter 3 of the register () method .

uses

File: Controllers / accounts.php
<?php namespace Project\Controllers;

use User, Post;

class Accounts
{
    public function register()
    {
        if( Post::submit() )
        {
            User::register
            ([
                'username' => Post::username(),
                'password' => Post::password(),
                'usermail' => Post::email(),
                'address'  => Post::address(),
                'phone'    => Post::mobilePhone()  
             ],  'users/login');
        }
    }
}

I have asked to be directed to the users / login page specified in parameter 2 after user registration above .


Combined Tables

If there are merged tables, member registration process should be done as follows.

User::register
([
     'table1' => ['column1' => 'value1', ...],
     'table2' => ['column1' => 'value2', ...]
]);

Auto Entry & Forwarding

We need to set the 2nd parameter to true by requesting automatic input . It should be used as follows for both auto entry and page orientation.

User::register
([
    'username' => Post::username(),
    'password' => Post::password() 
],  true);

if( User::isLogin() )
{
    redirect('users/login');
}

 

# Login ( ZN> = 1.0.0 )


It is used for user login.

Parameters

String $ User User name.
String $ password User password.
Mixed $ rememberMe = false Remember me? If this parameter is set to true, the next entry will be made automatically.
return Bool

Optional Methods

this username ( String $ username ) Can be used instead of parameter 1 of the login () method .
this password ( String $ password ) Can be used instead of parameter 2 of the login () method .
this remember ( Mixed $ remember ) Can be used instead of parameter 3 of the login () method .

uses

$status = User::login
(
    Post::username(), 
    Post::password(), 
    Post::rememberMe()
);

if( $status === true )
{
    redirect(URL::prev());
}

 

# IsLogin ( ZN >= 1.0.0 )


It is used to check whether the user is logged in.

Parameters

void
return Bool

uses

if( User::isLogin() )
{
    echo 'Hi, User';
}

 

# Data ( ZN >= 1.0.0 )


Gets the user information of the logged in user in array type.

Parameters

String $ tbl = NULL Table name. This parameter is used if working with merged tables.
return Object

uses

$data = User::data();

write('{0} - {1}', [$data->username, $data->email]);
ZNFramework - robot@znframework.com 

Combined Tables

If using unified user tables 1 which stated that the data required to be taken from the table parameter.

$profile = User::data('user_profile');
$user    = User::data('users');

write('{0} - {1}', [$user->username, $profile->address]);
ZNFramework - Istanbul / Turkey 

 

# Logout ( ZN >= 1.0.0 )


User is used to output.

Parameters

String $ redirect = NULL Address to be forwarded.
Int $ time = 0 Routing time.
return void

uses

User::logout(URL::prev(), 2);

 

# Update ( ZN >= 1.0.0 )


with the old password of the logged in user is used to update their password information and other available information.

Parameters

String $ oldpassword Current password.
String $ newpassword New password.
String $ newpassword New password again. Depends on demand. If NULL is specified, this parameter is assumed to be matched with the second parameter.
Array $ Otherdat to Updating of other user information other than password update is also indicated if required.
return Bool

Optional Methods

this oldPassword ( String $ oldPassword ) It can be used instead of parameter 1 of the update () method .
this newPassword ( String $ newPassword ) It can be used instead of parameter 2 of the update () method .
this passwordAgain ( String $ passwordAgain ) Can be used instead of parameter 3 of the update () method .
this column ( String $ columnName , String $ value ) Can be used instead of parameter 4 of the update () method .

uses

If you only want to update your password;

User::update(Post::oldPassword(), Post::newPassword());

Updating Other Information

If it is requested to update the password with other information;

User::update
(
    Post::oldPassword(),
    Post::newPassword(),
    NULL,
    [
        'name'  => Post::name(),
        'phone' => Post::phone(),
    ]
);

can be used like.


Combined Tables

If the user table consists of joined tables;

User::update
(
    Post::oldPassword(),
    Post::newPassword(),
    NULL,
    [
        'users' =>
        [
            'name'  => Post::name(),
            'phone' => Post::phone()
        ],

        'user_profile' =>
        [
            'first_name' => Post::firstName(),
            'last_name'  => Post::lastName()
        ]
    ]
);

as used.

 

# ForgotPassword ( ZN> = 1.0.0 )


The method of forgotten password.

Parameters

String $ email E-mail address.
String $ return Path Email return link
return Bool

uses

User::forgotPassword(Method::post('email'), 'users/login');

2. Forget the parameter cipher is included in the email that is sent to the link. When this link is clicked, it is specified which page is requested to be converted.


Verification Information ( ZN> = 5.4.6 )

Using only e-mail information to forgot password operation may cause some security problems. For this reason, a second security information is needed in addition to e-mail information . This is specified in the verification configuration in the above configuration, which security information will be kept on the table .

User::verification(Post::verification())->forgotPassword(Post::email(), 'users/login');

In the above usage, the verification information from the forms is used in the verification () method. This verification information should be a value that the users themselves specify.


Change Email Template

File: External / Resources / Templates / UserEMail / ForgotPassword.php

By editing this file, you can create a more visual e-mail template.

 

# SendEmailAll ( ZN> = 5.0.0 )


It was created to send e-mail to all registered users in the system.

Parameters

String $ subject The subject of e-mail.
String $ Message The contents of the email
return void

uses

User::sendEmailAll('New Topic', 'Added new topic.');

Attach File Attachment

If you want to attach a file to this email, you can use the attachment () method, which is an optional method . The parameters of the method are identical to those of the Email :: attachment () method.

User::attachment('path/topic.jpg')->sendEmailAll('New Topic', 'Added new topic');

 

# ActivationComplete ( ZN> = 1.0.0 )


If the activation column is specified in the settings, and the register parameter ( 3 ) of the register () method and the return link are specified, this method can be used. This method should be used on the return link specified page. That means you have to use it on the page you want to be reached via email. User activation is thus completed when a request is made to the specified page. The value that this column should hold should be set to 0 and 1 .

Parameters

void
return void

uses

The method that should be used on the page to be visited by return link.

User::activationComplete();

Change Email Template

File:  External / Resources / Templates / UserEMail / Activation.php

By editing this file, you can create a more visual e-mail template.

 

# ResendActivationEmail ( ZN >= 5.5.1 )


It is used to resend the activation e-mail in case of no reason.

Parameters

String $ Username Your username should include your email information. If the user does not have e-mail information, the third parameter should be the e-mail address.
String $ return Link It href=""sets the value of the link in the activation e-mail . The user is a return link.
String $ email = NULL If the parameter 1 (user name) does not have an e-mail attribute, this parameter should carry the e-mail information to send the e-mail.
return Bool

uses

User::resendActivationLink($username, 'profile/activation', $usermail);

 

# Count ( ZN >= 2.0.0 )


It is used to learn the number of registered members.

Parameters

void
return Int

uses

echo User::count();

 

# ActiveCount ( ZN> = 2.0.0 )


Gets the number of logged in users. However, in order to use this method, the active column must be specified in the settings . The value that this column should hold should be set to 0 and 1 .

Parameters

void
return Int

uses

echo User::activeCount();

 

# BannedCount ( ZN >= 2.0.0 )


Gives the number of banished users. However, in order to use this method, the banned column must be specified in the settings . The value that this column should hold should be set to 0 and 1 .

Parameters

void
return Int

uses

echo User::bannedCount();

 

# Success ( ZN> = 2.0.0 )


Returns success information for user operations.

Parameters

void
return String

uses

echo User::success();

 

# Error ( ZN >= 2.0.0 )


Returns error information for user operations.

Parameters

void
return String

uses

echo User::error();