PHP Classes

File: app/request/new_partner.php

Recommend this page to a friend!
  Classes of Ali YILMAZ   PHP API Service   app/request/new_partner.php   Download  
File: app/request/new_partner.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP API Service
Implements a project API using the Mind framework
Author: By
Last change:
Date: 2 years ago
Size: 1,325 bytes
 

Contents

Class file image Download
<?php

if(empty($this->post)){
    return
null;
}

$this->post['partner_name'] = $this->post['partner_name'] ?? '';
$this->post['partner_password'] = $this->post['partner_password'] ?? '';

$rule = [
   
'partner_name'=>'required|min-char:3|max-char:20|unique:partners',
   
'partner_password'=>'required|min-char:6|max-char:16'
];

$message = [
   
'partner_name'=>[
       
'required'=>'Partner name is required',
       
'min-char'=>'Partner name must be at least 3 characters',
       
'max-char'=>'Partner name must be at most 16 characters',
       
'unique'=>'Partner name is already taken'
   
],
   
'partner_password'=>[
       
'required'=>'Partner password is required',
       
'min-char'=>'Partner password must be at least 6 characters',
       
'max-char'=>'Partner password must be at most 16 characters'
   
]
];

if(
$this->validate($rule, $this->post, $message)){

   
$values = [
       
'partner_name'=>$this->post['partner_name'],
       
'partner_password'=>md5($this->post['partner_password']),
       
'partner_token'=>$this->generateToken(14),
       
'partner_status'=>true,
       
'created_at'=>$this->timestamp
   
];

    if(
$this->insert('partners', $values)){
        echo
'Partner added.';
    } else {
        echo
'Partner not added.';
    }
} else {
   
$this->print_pre($this->errors);
}