<?php
namespace App\Http\Controllers\Api\V1\User\Auth;
use Exception;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Helpers\Response;
use App\Http\Controllers\Controller;
use App\Traits\User\RegisteredUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules\Password;
use App\Providers\Admin\BasicSettingsProvider;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers, RegisteredUsers;
protected $basic_settings;
public function __construct()
{
$this->basic_settings = BasicSettingsProvider::get();
$this->middleware(function($request, $next) {
if($this->basic_settings->user_registration == false) return Response::error([__("Currently user registration is not available")], [], 400);
return $next($request);
});
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function register(Request $request)
{
$validator = $this->validator($request->all());
if($validator->fails()) {
return Response::error($validator->errors()->all(),[]);
}
$validated = $validator->validate();
$basic_settings = $this->basic_settings;
$validated['email_verified'] = ($basic_settings->email_verification == true) ? false : true;
$validated['sms_verified'] = ($basic_settings->sms_verification == true) ? false : true;
$validated['kyc_verified'] = ($basic_settings->kyc_verification == true) ? false : true;
$validated['password'] = Hash::make($validated['password']);
$validated['username'] = make_username($validated['firstname'],$validated['lastname']);
if(User::where("username",$validated['username'])->exists()) return Response::error([__('User already exists!')],[],400);
try{
event(new Registered($user = $this->create($validated)));
}catch(Exception $e) {
return Response::error([__('Registration failed! Please try again')],[],500);
}
// get user with all information
try{
$user = User::find($user->id);
}catch(Exception $e) {
return Response::error([__('Failed to fetch user information. Please try again')],[],500);
}
try{
$token = $user->createToken("auth_token")->accessToken;
}catch(Exception $e) {
return Response::error([__('Failed to generate user token! Please try again')],[],500);
}
return $this->registered($request, $user, $token);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validator(array $data) {
$basic_settings = $this->basic_settings;
$password_rule = "required|string|min:6";
if($basic_settings->secure_password) {
$password_rule = ["required",Password::min(8)->letters()->mixedCase()->numbers()->symbols()->uncompromised()];
}
return Validator::make($data,[
'firstname' => 'required|string|max:60',
'lastname' => 'required|string|max:60',
'email' => 'required|string|email|max:150|unique:users,email',
'password' => $password_rule,
]);
}
/**
* Get the guard to be used during registration.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard("api");
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
return User::create($data);
}
/**
* The user has been registered.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function registered(Request $request, $user, $token)
{
try{
$mail_response = [];
if($user->email_verified == false) {
$mail_response = AuthorizationController::sendCodeToMail($user);
}
}catch(Exception $e) {
$user->delete();
return Response::error([$e->getMessage()],[],500);
}
try{
$this->createUserWallets($user);
$this->createMerchant($user);
}catch(Exception $e) {
$this->guard()->logout();
$user->delete();
return Response::error([__('Registration Failed! Something went wrong! Please try again')],[],500);
}
return Response::success([__('User successfully registered')],[
'token' => $token,
'user_info' => $user->only([
'id',
'firstname',
'lastname',
'fullname',
'username',
'email',
'mobile_code',
'mobile',
'full_mobile',
'email_verified',
'kyc_verified',
'two_factor_verified',
'two_factor_status',
'two_factor_secret',
]),
'authorization' => [
'status' => count($mail_response) > 0 ? true : false,
'token' => $mail_response['token'] ?? "",
],
],200);
}
}
At NFC Pay, your privacy is of utmost importance to us. This Privacy Policy outlines how we collect, use, share, and protect your personal information when you use our services, including our website and mobile applications.
1. Information We Collect
2. How We Use Your Information
We use the information we collect for the following purposes:
3. Sharing Your Information
We may share your personal information in the following circumstances:
4. Security of Your Information
We take the security of your personal information seriously and implement a variety of security measures, including encryption, secure servers, and access controls, to protect your data from unauthorized access, disclosure, alteration, or destruction. However, no method of transmission over the internet or electronic storage is completely secure, and we cannot guarantee its absolute security.
5. Your Privacy Rights
Depending on your location, you may have certain rights regarding your personal information, such as:
6. Third-Party Links
Our services may contain links to third-party websites or services. We are not responsible for the privacy practices or the content of these third-party sites. We encourage you to review the privacy policies of those third parties.
7. Children’s Privacy
Our services are not intended for individuals under the age of 13. We do not knowingly collect personal information from children under 13. If we become aware that we have collected personal information from a child under 13, we will take steps to delete that information.
8. Changes to This Privacy Policy
We may update this Privacy Policy from time to time to reflect changes in our practices or for other operational, legal, or regulatory reasons. We will notify you of any significant changes by posting the new Privacy Policy on our website and updating the effective date.
9. Contact Us
If you have any questions or concerns about this Privacy Policy or our data practices, please contact us at:
Email: support@nfcpay.com