Please I have a laravel website which have been working fine then all of a sudden when a user uses a referral link to register, the page will reload and redirect back to the registration page. I tried it for few times and it works then I used the new referral link to register another new account and didn't work again ever since then. And its not showing any error message but rather bounce back to same page. I have checked the RegistrationController and all the code is still fine as same before. Please I really need this help.
Thanks in Advance
Below is my RegistrationControl
`public function getRegistrationPage(){
return view('auth.register');
}
public function storeUser(Request $request){
$this->validate($request, [
'name' => 'required|max:30',
'email' => 'required|unique:users',
'phone' => 'required|min:10|unique:users',
'username' => 'required|min:5|unique:users|regex:/^\S*$/u',
'password' => 'required|string|min:6|confirmed',
'country' => 'required',
'state' => 'required',
]);
$email_code = strtoupper(Str::random(6));
$email_time = Carbon::parse()->addMinutes(5);
$phone_code = strtoupper(Str::random(6));
$phone_time = Carbon::parse()->addMinutes(5);
$upliner = Cookie::get('referral');
$uplinerUsername = Cookie::get('referral');
$email_verify = 1;
$phone_verify = 1;
$user = new User();
if($upliner == null){
$upliner = 0;
}
else{
$chkUserRef = User::where('reference', $upliner)->first();
if($chkUserRef == null){
return redirect('register');
}else{
$user_id = $chkUserRef->id;
$upliner = $user_id;
}
}
$data['name'] = $user->name = $request['name'];
$data['email'] =$user->email = $request['email'];
$user->phone = $request['phone'];
$data['username'] = $user->username = $request['username'];
$user->reference = $request['username'];
$user->country = $request['country'];
$user->state = $request['state'];
$user->under_reference = $upliner;
$user->email_verify = $email_verify;
$user->email_code = $email_code;
$user->email_time = $email_time;
$user->phone_verify = $phone_verify;
$user->phone_code = $phone_code;
$user->phone_time = $phone_time;
$data['password'] = $user->password = bcrypt($request['password']);
$saved = $user->save();
if($saved){
//send mail to the registered user
Mail::send('emails.welcome-email', ['data' => $data], function ($message) use ($data) {
$message->from('noreply#example.com', 'example.com')
->to($data['email'], $data['username'], $data['name'])
->subject('Welcome Email');
});
//send mail to Admin
$data['adminEmail'] = "example#gmail.com";
Mail::send('emails.registration-notification', ['data' => $data], function ($message) use ($data) {
$message->from('noreply#example.com', 'example.com')
->to($data['adminEmail'], $data['username'], $data['email'], $data['name'])
->subject('User Registeration Notification');
});
//send mail to referrer
if($uplinerUsername != null){
$chkReff = User::where('username',$uplinerUsername)->first();
if($chkReff == null){
return redirect('register');
}
else{
//get the person's details and send mail
$userReff = User::where('username',$uplinerUsername)->first();
$data['userEmail'] = $userReff->email;
$data['refUsername'] = $userReff->username;
Mail::send('emails.referral-notification', ['data' => $data], function ($message) use ($data) {
$message->from('noreply#example.com', 'example.com')
->to($data['userEmail'], $data['username'],
$data['refUsername'], $data['userEmail'], $data['email'], $data['name'])
->subject('Referral Notification');
});
}
}
return redirect('login');
}
`
Related
Client error: POST https://discordapp.com/api/oauth2/token resulted in a 429 Too Many Requests response: {"code": 0, "message": "You are being blocked from accessing our API temporarily due to exceeding our rate limits freque (truncated...)
I am getting this error when i am trying to login into my web apllication using discord,I know i am exceeding rate limits i want to increase my rate limit,after sometime it has started working again but i do not want this error again cause i have live customer on my site
<?php
namespace App\Http\Controllers\Auth;
include base_path('vendor/autoload.php');
use RestCord\DiscordClient;
use App\Http\Controllers\Controller;
use App\Models\User;
use Laravel\Socialite\Facades\Socialite;
use App\Notifications\SendCredentials;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class DiscordLoginController extends Controller
{
public function login(){
return Socialite::with('discord')->scopes(['guilds','guilds.join'])->redirect(); //redirect to generated 0auth link
}
public function callback(){
function getTotalMembers($last_id, $membrs_total)
{
$discord = new DiscordClient(['token' => getenv('DISCORD_BOT_TOKEN')]);
if ($last_id == 0) {
$members = $discord->guild->listGuildMembers(['guild.id' => 815031226699874334, 'limit' => 1000]);
} else {
$members = $discord->guild->listGuildMembers(['guild.id' => 815031226699874334, 'limit' => 1000, 'after' => $last_id]);
}
$end = end($members);
$last_id = $end->user->id;
$membrs_total = array_merge($membrs_total, $members);
if (count($members) <= 999) {
return $membrs_total;
} else {
return getTotalMembers($last_id, $membrs_total);
}
}
$membrs_total = array();
$membrs_totals = getTotalMembers(0, $membrs_total);
$current_guilds_ids=array();
foreach($membrs_totals as $member){
array_push($current_guilds_ids,$member->user->id);
}
$user = Socialite::driver('discord')->stateless()->user();
if(in_array($user->id,$current_guilds_ids))
{
$accessTokenResponseBody = $user->accessTokenResponseBody;
if (!Auth::user()) { //handle user login
$users = User::where(['discord_id' => $user->id])->first();
if ($users) {
if(in_array($users->discord_id,$current_guilds_ids)){
User::where(['id' => $users->id])->update([ 'is_binded' => true,'is_verified'=>true]);
}
Auth::login($users);
return redirect()->route('home');
} else {
$users = User::where('email', $user->email)->first();
if (!$users) {
$users = new User();
$users->name = $user->name;
$users->email = $user->email;
$password = uniqid();
$users->password = Hash::make($password);
$users->discord_id = $user->id;
$users->discord_email = $user->email;
$users->is_binded = 1;
if ($user->user['verified'] == 1) {
$users->is_verified = 1;
}
$users->save();
$notifyUsers = User::where('email', $users->email)->get();
foreach ($notifyUsers as $notifyUser) {
$notifyUser->notify(new SendCredentials($notifyUser, $password));
}
Auth::login($users);
return redirect()->route('home');
}
}
} else {
$user_id = auth()->user()->id;
$users = User::where(['discord_id' => $user->id])->count();
if ($users == 0) {
User::where(['id' => $user_id])->update(['discord_id' => $user->id, 'discord_email' => $user->email, 'is_binded' => true]);
return redirect()->route('home');
} else {
User::where(['id' => $user_id])->update(['discord_id' => $user->id, 'discord_email' => $user->email, 'is_verified' => false]);
$customer_status = User::where(['id' => $user_id])->value('is_customer');
$client = new \GuzzleHttp\Client();
$request = $client->get( //perform check
'https://discordapp.com/api/users/#me/guilds',
[
'headers' => [
'Authorization' => 'Bearer ' . $accessTokenResponseBody['access_token'],
],
]
);
$response = json_decode($request->getBody()->getContents(), true); //decode response
foreach ($response as $key => $value) { //traverse result
if ($value['id'] == 815031226699874334) {
User::where(['id' => $user_id])->update(['is_verified' => true]);
alert()->success('Nice One', 'You are in SMT Proxies Discord.');
if ($customer_status == true) {
$client = new Client([
'headers' => [
'Authorization' => 'Bot ' . getenv('DISCORD_BOT_TOKEN'),
"Content-Type" => "application/json"
]
]);
$client->put('https://discordapp.com/api/guilds/815031226699874334/members/' . $user->id . '/roles/815046198791503914', []);
alert()->success('Nice One', 'You are in SMT Proxies Discord & got customer role');
}
break;
}
}
return redirect()->route('home');
}
}
}
else{
alert()->warning('Sorry You have to join our server first');
return redirect()->route('login');
}
}
}
my controller look like
public function react(Request $request){
//echo "hi";
//return;
//return response()->json($request);
$this->validate($request, [
'postid' => 'required',
'react' => 'required'
]);
$reaction = Reaction::firstOrNew([
'post_id'=>$request->postid,
'user_id'=> Auth::id()
]);
$reaction->user_id = Auth::id();
$reaction->type = $request->react;
$reactType = "";
if ($request->react === "l"){$reactType = "liked";}
else if ($request->react === "d"){$reactType = "disliked";}
else if ($request->react === "h"){$reactType = "loved";}
else if ($request->react === "s"){$reactType = "Smiled";}
else{}
$post = Post::find($request->postid);
$postuser = $post->user->name;
if($post->reactions()->save($reaction)){
$data['message'] = Auth::user()->name.' '.$reactType. ' a Post from' . $postuser;
$data['type'] = 'reaction';
**$this->p->trigger('user-'.$post->user_id, 'new-post', $data);**
return response()->json([
'success' => true,
'message' => 'Reacted'
]);
}
else{
return response()->json([
'success' => false,
'message' => 'Error'
]);
}
AND I AM UNABLE TO LINK WITH PUSHER CHANNEL
But I keep getting an error
Undefined property: App\Http\Controllers\MyController::$p
What am I doing wrong? Would highly appreciate any possible help!
property $this->p (p) , You have not set the value
$this->p = Value ;
After setting, you can use the information.
$this->p->trigger('user-'.$post->user_id, 'new-post', $data);
In the code written above, $this->p has an null value
$this->null->trigger('user-'.$post->user_id, 'new-post', $data);
In fact, this is how you use it
Here is my code for validation.
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|email|unique:users',
'phone' => 'required|unique:users',
'user_name' => 'required|unique:users',
'operator_name' => 'required|max:255',
'operator_nid' => 'required|numeric|unique:operators',
'operator_password' => 'required',
'operator_gender' => 'required',
'operator_birthday' => 'required',
]);
if ($validator->fails()) {
return redirect('operator/create')
->withErrors($validator)
->withInput();
}
$user = new User;
$user->name = $request->operator_name;
$user->email = $request->email;
$user->phone = $request->phone;
$user->user_name = $request->user_name;
$user->password = bcrypt($request->password);
$user->type = 3;
$user->save();
$operator = new Operator;
$operator->operator_name = $request->operator_name;
$operator->operator_email = $request->email;
$operator->operator_phone = $request->phone;
$operator->operator_nid = $request->operator_nid;
$operator->operator_user_name = $request->user_name;
$operator->user_id = $user->id;
$operator->type = 3;
$operator->operator_gender = $request->operator_gender;
$operator->operator_birthday = $request->operator_birthday;
$operator->operator_occupation = $request->operator_occupation;
$operator->operator_facebook = $request->operator_facebook;
$operator->operator_twitter = $request->operator_twitter;
$operator->operator_gplus = $request->operator_gplus;
$operator->operator_address = $request->operator_address;
if ($request->hasfile('operator_pro_pic')){
$image = $request->file('operator_pro_pic');
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('images/operator/' . $filename);
Image::make($image)->resize(950, 700)->save($location);
$operator->operator_pro_pic = $filename;
}
$operator->save();
return $user;
}
I am trying to create an operator and a user at the same time. email, phone and user_name should be unique in the user's table and other data will be validate from the operators table. Validation is working as it is giving me the errors but after validating it's not going further. So my code after the validation is not executing. What is the possible reason for this?
You can use -
if ($validator->fails()) {
return back()->withInput()
->withErrors($validator);
}
The better way will be to create a request file by using
php artisan make:request requestName
define all the validation in there. In this case if your validation fails the application will return back with error and old-inputs without reaching to the controller.
I have a form and it's been bugging for a while now, when i have all the information filled up in the forms it seems to insert it very quick, however if one or more fields are empty it doesn't work at all
the query i am using to insert into the database is. i am trying to figure out if i can use Insert_delay and maybe it will solve the problem? any possible solutions or changes i need to do
function student($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect('login', 'refresh');
if ($param1 == 'create') {
$data['name'] = $this->input->post('name');
$data['sex'] = $this->input->post('sex');
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('email');
$data['password'] = $this->input->post('password');
$data['year'] = $this->input->post('year');
$data['rate'] = $this->input->post('rate');
$data['class_id'] = $this->input->post('class_id');
$data['class_id2'] = $this->input->post('class_id2');
$data['class_id3'] = $this->input->post('class_id3');
$data['class_id4'] = $this->input->post('class_id4');
$data['parent_id'] = $this->input->post('parent_id');
$data['roll'] = $this->input->post('roll');
$this->db->insert_('student', $data);
$student_id = $this->db->insert_id();
$this->session->set_flashdata('flash_message' , get_phrase('Student_added_successfully'));
$this->email_model->account_opening_email('student', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
redirect(base_url() . 'index.php?admin/student_add/' . $data['class_id'], 'refresh');
In controller
function student($param1, $param2 $param3 )
{
if ($this->session->userdata('admin_login') != 1)
{
redirect('login', 'refresh');
}
else
{
if($param1 == 'create') {
$result = $this->model_name->insert_data();
if ($result != FALSE) {
$email => $this->input->post('email');
$confirm = $this->email_model->account_opening_email('student', $email); # do same as insert
if ($confirm != FALSE) {
$this->session->set_flashdata('flash_message' , get_phrase('Student_added_successfully'));
redirect(base_url() . 'index.php?admin/student_add/' . $data['class_id'], 'refresh');
}
else
{
echo "Mail send failed";
}
}
else
{
echo "param1 is not create";
}
}
}
}
In Model
public function insert_data()
{
# to isert data, I add them in to one array
$data = array(
'name' => $this->input->post('name'),
'sex' => $this->input->post('sex'),
'address' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'year' => $this->input->post('year'),
'rate' => $this->input->post('rate'),
'class_id' => $this->input->post('class_id'),
'class_id2' => $this->input->post('class_id2'),
'class_id3' => $this->input->post('class_id3'),
'class_id4' => $this->input->post('class_id4'),
'parent_id' => $this->input->post('parent_id'),
'roll' => $this->input->post('roll')
);
if (!$this->db->insert('student', $data)) {
# insert FAILED
return FALSE;
}
else{
# insert SUCCESS
$slast_id = $this->db->insert_id(); # get last insert ID
return = $slast_id;
}
}
I am fairly new to everything and I am wondering if it is possible to store declared variables in to database?
For example(these are placed in the nameoffilecontroller.php),
public function onewayflightshow()
{ $a=Session::get('children');
$b=Session::get('adult');
$c=Session::get('infant');
$d=Session::get('destinationto');
$e=Session::get('destinationfrom');
$f=Session::get('departure');
$results = DB::table('oneways')->get();
if (!empty($results))
foreach ($results as $user)
{
$adultFee = ($user->fare)*$b;
/*------------------------Child Fee------------------------*/
$partialFee1 = ($user->fare)*.05;
$partialFee2 = ($user->fare)-$partialFee1;
$childFee = $partialFee2*$a;
/*------------------------Infant Fee------------------------*/
$partialFee3 = ($user->fare)*.10;
$partialFee4 = ($user->fare)-$partialFee3;
$infantFee = $partialFee2*$c;
$payment = ($adultFee+$childFee+$infantFee);
var_dump($payment);
}
$rules = array(
'title' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'cemail' => 'required|same:email',
'firstname' => 'required',
'middlename' => 'required',
'birthday' => 'required',
'city' => 'required',
'streetadd' => 'required',
'zipcode' => 'required|max:4',
'country' => 'required',
'home' => 'required|max:7',
'mobile' => 'required|max:12'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
return View::make('content.onewayflightfillup')->withErrors($validator);
} else {
$reserve = new Reserves;
$reserve->title = Input::get('title');
$reserve->lastname = Input::get('lastname');
$reserve->firstname= Input::get('firstname');
$reserve->middlename = Input::get('middlename');
$reserve->birthday = Input::get('birthday');
$reserve->city = Input::get('city');
$reserve->streetadd = Input::get('streetadd');
$reserve->zipcode = Input::get('zipcode');
$reserve->country = Input::get('country');
$reserve->home = Input::get('home');
$reserve->work = Input::get('work');
$reserve->fax = Input::get('fax');
$reserve->mobile = Input::get('mobile');
$reserve->email = Input::get('email');
$reserve->children = Session::get('children');
$reserve->children = Session::get('adult');
$reserve->children = Session::get('infant');
$reserve->children = Session::get('destinationfrom');
$reserve->children = Session::get('destinationto');
$reserve->children = Session::get('departure');
$reserve->$payment; <-- IS THIS EVEN POSSIBLE?
$reserve->save();
var_dump($reserve);
return View::make('content.onewayflightbooklist');
}}
I am trying to save(); everything in my database, from the session variables to the inputed values from the user but the problem is I don't know how to insert $payment into the database table. Is it even possible? If yes, what are the way/s of doing it?
You need to put it into database using:
$reserve->payment = $payment;
but of course in your table you need to have column with name payment
And obviously this:
$reserve->children = Session::get('children');
$reserve->children = Session::get('adult');
$reserve->children = Session::get('infant');
$reserve->children = Session::get('destinationfrom');
$reserve->children = Session::get('destinationto');
$reserve->children = Session::get('departure');
won't work. In each column you can insert only one data.
<?php
class Test extends Eloquent
{
public function insert()
{
$a=1;
$b=2;
$c=$a+$b;
$data = array('column_1'=>$a , 'column_2'=>$b , 'column_3'=>$c);
$query = DB::table('table_name')->insert($data);
}
}
?>
This is a model function extending eloquent ORM . call this model function in your controller
class TestController extends BaseController
{
public function test()
{
$data = Modelname::ModelFunction(); /* if the model function is static */
/* else you need to create an object for that class */
$t = new Modelname();
$data = $t->ModelFunction();
}
}