Sending mail using Laravel 4.2 and Mailgun - mailgun

i'm little bit new to this.
I had read the documentation of Laravel 4 and some of the Mailgun, I had tested some mail and worked but just in route like this:
Route::get('send_test_email', function(){
Mail::send('emails.registro', array('key' => 'value'), function($message)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to('luis02lopez#hotmail.com');
});
});
I went to myapp/send_test_email in the browser and get an email.
But now I want to send an email at registration, I created the route:
Route::get('mail', ['uses' => 'MailController#send', 'as' => 'send']);
The controller:
<?php
class MailController extends \BaseController {
public function index()
{
return View::make('signup');
}
public function send() {
Mail::send('emails.registro', $data, function($message) use
           {
           $message->subject('Bienvenido a la gran experiencia');
           
           $message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
           
           $message->to($user->email, $user->firstname);
           });
}
And added a form to the signup form like this:
{{ Form::open(['route' => 'send', 'method' => 'get']) }}
<div class="form-group">
{{ Form::label('username', 'Usuario', ['class' => 'sr-only']) }}
{{ Form::text('username', null, ['placeholder' => 'Usuario', 'required', 'minlength' => 6, 'class' => 'form-control', ]) }}
#foreach($errors->get('username', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password', 'Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password', ['placeholder' => 'Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password_confirm', 'Confirmar Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password_confirmation', ['placeholder' => 'Confirmar Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password_confirmation', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'sr-only']) }}
{{ Form::email('email', null, ['placeholder' => 'Email', 'required', 'class' => 'form-control']) }}
#foreach($errors->get('email', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('firstname', 'Nombres', ['class' => 'sr-only']) }}
{{ Form::text('firstname', null, ['placeholder' => 'Nombres', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('lastname', 'Apellidos', ['class' => 'sr-only']) }}
{{ Form::text('lastname', null, ['placeholder' => 'Apellidos', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::submit('Registrar', ['class' => 'btn btn-lg btn-block btn-kinbu'])}}
</div>
{{ Form::close() }}
And I got a Parse error: syntax error, unexpected 'Mail' (T_STRING) in the controller, why?

Here I have errors:
public function send() {
Mail::send('emails.registro', $data, function($message) use
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}
I'm using the $user var, but I'm not passing it with the closure "user" so I have to do:
public function send() {
Mail::send('emails.registro', array('key' => 'value'), function($message) use ($user)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}

Related

livewire validation is working real-time message "required.validation" show this Problem

livewire validation is working real-time message show "required.validation" but I see the display message "first_name field is required"
This is my livewire component code
public $first_name = '';
public $last_name = '';
public $email = '';
public $phone_number = '';
public $password = '';
public $password_confirmation = '';
public $business_name = '';
public $comments = '';
public $solutions_of_interest = '';
protected $rules = [
'first_name' => 'required',
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'phone_number' => 'required|digits:9',
'business_name' => 'required|max:255',
'solutions_of_interest' => 'required|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|min:8|confirmed',
'password_confirmation' => 'required|min:8',
];
public function save()
{
$this->validate();
User::create([
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'email' => $this->email,
'phone_number' => $this->phone_number,
'password' => Hash::make($this->password),
'business_name' => $this->business_name,
'comments' => $this->comments,
'solutions_of_interest' => $this->solutions_of_interest,
'email_verified_at' => Carbon::now(),
'phone_number_varified' => 1,
]);
// $this->reset();
session()->flash('success','User Created Successfully.');
}
public function updated($property)
{
$this->validateOnly($property);
}
this is my livewire blade component code
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
<input type="text" class="form-control" wire:model="first_name"
autocomplete="first_name" autofocus placeholder="First Name">
#error('first_name') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
<input type="text" class="form-control" wire:model="last_name"
autocomplete="last_name" autofocus placeholder="Last Name">
#error('last_name')
<span class="text-danger">{{ $message }}</span>
#enderror
</div>
see this image
enter image description here
can you try customize your validation messages:
https://laravel-livewire.com/docs/2.x/input-validation#customize-error-message-and-attributes

I want to add a custom png image instead of glyphicon in admin menu section in opencart 2.3x and 3x?

how do i update this, in column_left controller?
if ($catalog) {
$data['menus'][] = array(
'id' => 'menu-catalog',
'icon' => 'fa-tags',
'name' => $this->language->get('text_catalog'),
'href' => '',
'children' => $catalog
);
}
you can't because it is hardcoded for evey menu,
and even you manage to get this done , some other extension you installed still need that update fix
in column left controller
'icon' => 'fa-tags', chaange it to 'icon' => 'glyphicon glyphicon-user'
nothing to change in view , it will work ,
You should customize the html in "admin/view/template/common/column_left.twig"
For example .. replace this code :
{% if menu.href %}<i class="fa {{ menu.icon }} fw"></i> {{ menu.name }}
by:
{% if menu.href %}{% if menu.img %}<img src="{{ menu.img }}"> {{ menu.name }}{% else %}<i class="fa {{ menu.icon }} fw"></i> {{ menu.name }}{% endif %}
and adding the image path in menu array item in column_left controller :
'img' => 'view/image/file.png'

Template Parse Erros Angular "<" (" with Django REST framework

I've been trying to create a DRF API with an Angular front end for an existing project that I have. I've created a serializer for User and Device. I tried removing multiple pieces of the HTML component, managing to result in a different error, StaticInjectorError(AppModule -> DevicePostService).
I'm still pretty new to Angular so what it seems like the error is coming from is the fact that my devicepostservice is not getting served to the web page for some reason.
Console error:
[Error] Error: Template parse errors:
Unexpected character "<" ("
<div class="col-sm-4">
<button (click)="login()" class="btn btn-primary">Log In</button
[ERROR ->]</div>
<div class="col-sm-12">
<span *ngFor="let error of _userService.errors.non_field_errors""): ng:///AppModule/AppComponent.html#15:2
Unexpected closing tag "div". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags ("
<div class="col-sm-4">
<button (click)="login()" class="btn btn-primary">Log In</button
[ERROR ->]</div>
<div class="col-sm-12">
<span *ngFor="let error of _userService.errors.non_field_errors""): ng:///AppModule/AppComponent.html#15:2
Unexpected closing tag "div". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (" <span *ngFor="let error of _userService.errors.non_field_errors">{{ error }}<br /></span>
</div>
[ERROR ->]</div>
<div class="row" *ngIf="_userService.token">
<div class="col-sm-12">You are logged in as {{ "): ng:///AppModule/AppComponent.html#19:0
_preparseLoadedTemplate (vendor.js:24658)
normalizeTemplate (vendor.js:24635)
loadDirectiveMetadata (vendor.js:26827)
(anonymous function) (vendor.js:34471)
forEach
(anonymous function) (vendor.js:34470)
forEach
_loadModules (vendor.js:34467:83)
_compileModuleAndComponents (vendor.js:34445)
compileModuleAsync (vendor.js:34405)
bootstrapModule (vendor.js:53721)
./src/main.ts (main.js:326:116)
__webpack_require__ (runtime.js:79)
(anonymous function) (main.js:339)
__webpack_require__ (runtime.js:79)
checkDeferredModules (runtime.js:46)
webpackJsonpCallback (runtime.js:33)
Global Code (main.js:1)
App.component.html
<h2>Log In</h2>
<div class="row" *ngIf="!_userService.token">
<div class="col-sm-4">
<label>Username:</label><br />
<input type="text" name="login-username" [(ngModel)]="user.username">
<span *ngFor="let error of _userService.errors.username"><br />
{{ error }}</span></div>
<div class="col-sm-4">
<label>Password:</label><br />
<input type="password" name="login-password" [(ngModel)]="user.password">
<span *ngFor="let error of _userService.errors.password"><br />
{{ error }}</span>
</div>
<div class="col-sm-12">
<span *ngFor="let error of _userService.errors.non_field_errors">{{ error }}<br /></span>
</div>
</div>
<div class="row" *ngIf="_userService.token">
<div class="col-sm-12">You are logged in as {{ _userService.username }}.<br />
Token Expires: {{ _userService.token_expires }}<br />
<button (click)="refreshToken()" class="btn btn-primary">Refresh Token</button>
<button (click)="logout()" class="btn btn-primary">Log Out</button>
</div>
</div>
<!--
<h2 class="mt-3">Devices</h2>
<div *ngFor="let device of devices">
<div class="row mb-3">
<label class="col-md-2">Owner:</label>
<div class="col-md-2 mb-1">{{ device.owner }}</div>
<label class="col-md-2">Brand:</label>
<div class="col-md-6">{{ device.brand }}</div>
<div class="col-md-12">{{ device.name }}</div>
</div>
</div>-->
App.component.ts
import {Component, OnInit} from '#angular/core';
import {DevicePostService} from './device_post.service';
import {UserService} from './user.service';
import {throwError} from 'rxjs';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
/**
* An object representing the user for the login form
*/
public user: any;
public devices;
public new_device: any;
constructor(private _devicePostService: DevicePostService, private _userService: UserService) { }
ngOnInit() {
this.getDevices();
this.new_device = {};
this.user = {
username: '',
password: ''
};
}
getDevices() {
this._devicePostService.list().subscribe(
data => {
this.devices = data;
},
err => console.error(err),
() => console.log('done loading devices')
)
}
updateDevice () {
this._devicePostService.create(this.new_device, this.user.token).subscribe(
data => {
this.getDevices();
return true;
},
error => {
console.error('Error saving!');
return throwError(error);
}
);
}
login() {
this._userService.login({'username': this.user.username, 'password': this.user.password});
}
refreshToken() {
this._userService.refreshToken();
}
logout() {
this._userService.logout();
}
}
Seems like you have a basic syntax error in your template
<button (click)="login()" class="btn btn-primary">Log In</button
should be
<button (click)="login()" class="btn btn-primary">Log In</button>
(note the final '>' character)

Angular and Rails not able to create a user with the data sent

I have a Rails 4 api with devise gem with an angular frontend. When i send a user json object the post parameters are sent but rails doesn't seem to like the format:
The Json object sent from the angular to the rails api is:
Resource {first_name: "test first", last_name: "test last", email: "test#test.com", password: "testpass", password_confirmation: "testpass"}
but the data is received by rails as:
Parameters: Parameters: {"first_name"=>"test first", "last_name"=>"test last", "email"=>"test#test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "user"=>{"email"=>"test#test.com", "first_name"=>"test first", "last_name"=>"test last"}}
and fails on the validation: ["Password can't be blank"]. Which shows it expects the user object format, but why isn't the password and password confirmation being added here?
I'm not sure whether i'm doing something wrong with Angular or Rails. If i send a request from Angular formatted as:
$scope.user = new User({user: {first_name: 'test first',
last_name: 'test last',
email: 'test#test.com',
password: 'testpass',
password_confirmation: 'testpass'}});
then this works:
SQL (0.7ms) INSERT INTO "users" ("created_at", "email", "encrypted_password", "first_name", "last_name", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sun, 29 Jun 2014 11:25:47 UTC +00:00], ["email", "test#test.com"], ["encrypted_password", "$2a$10$p70dQldL.b1SnyQFacr9YechtPOxLLNCjyuawiY/iPJGu4YgoQYV."], ["first_name", "test first"], ["last_name", "test last"], ["updated_at", Sun, 29 Jun 2014 11:25:47 UTC +00:00]]
but $scope.user = new User(); doesn't. Here is my code:
Users angular controller:
angular
.module('app')
.controller('UsersCtrl', ['User', '$scope', '$route', function(User, $scope, $route) {
$scope.user = new User();
$scope.users = User.query();
$scope.save = function() {
$scope.user.$save();
$scope.users.push($scope.user);
$scope.user = new User();
};
}]);
Angular users service
angular
.module('app')
.factory('User', function($resource) {
var User = $resource('http://0.0.0.0:3000/api/v1/users/:id.json', {id: '#id'}, {
update: {
method: 'PUT'
}
});
return User;
});
user rails controller
def new
respond_with(User.new)
end
def create
#user = User.new(user_params)
if #user.save
render :json => { :success => true }
else
Rails.logger.debug #user.errors.full_messages
render :json => { :errors => #user.errors.full_messages }, :status => :unprocessable_entity
end
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end
angular view
<form class="form-horizontal" ng-submit="save(user)">
<div class="control-group">
<label class="control-label" for="inputFirstName">First Name:</label>
<div class="controls">
<input type="text" id="inputFirstName" ng-model="user.first_name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputLastName">Last Name:</label>
<div class="controls">
<input type="text" id="inputLastName" ng-model="user.last_name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email:</label>
<div class="controls">
<input type="text" id="inputEmail" ng-model="user.email"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password:</label>
<div class="controls">
<input type="text" id="inputPassword" ng-model="user.password"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPasswordConfirmation">Password Confirmation:</label>
<div class="controls">
<input type="text" id="inputPasswordConfirmation" ng-model="user.password_confirmation"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Create user</button>
</div>
</div>
</form>

#if statement using URL parameter laravel blade

I am new to laravel and blade. I'm a student doing a simple 'job seeker' assignment. I have 2 different types of users - jobseekers (category 1) and employers (category 2). When I create a new user from buttons in layout.blade.php, users will click on a register (category 1) link or an Employer Button (category 2), I want to pass the category on to the create.blade.php so that I can stylise it depending on what category they are, and of course keep that information hidden from the actual User.
I'm not sure what code you want to see, but I'll start with my layout.blade.php - when the link or button is clicked, it redirects to create.blade.php and the url updates to either category 1 or categoy 2 - depending on what is clicked. I want to add an #if statement as to which create for gets displayed, one jobseeker or one for employer (they have slightly different options)
layout.blade.php
<div class="col-sm-9">
#if (!Auth::check())
<div class="login-form">
{{ Form::open(array('action' => 'UserController#login')); }}
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }}
{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }}
{{ Form::submit('Sign in', array('class' => 'btn btn-danger')); }}
{{ Form::close(); }}
{{ Form::open(array('action' => 'UserController#create')); }}
{{link_to_route('user.create', 'or Register here', ['category' => 1] )}}
</div>
{{link_to_route('user.create', 'Employers', ['category' => 2], array('class' => 'btn btn-primary')) }}
#endif
#yield('content1')
create.blade.php
#extends('job.layout')
#section('content1')
#if('category' == 2)
<h1>New Employer page</h1>
{{ Form::open(array('action' => 'UserController#store')); }}
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }}
<p>{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }}
{{ Form::hidden('category', 2) }}
{{ Form::label('name', 'Name:', array('class' => 'col-sm-3')) }}
{{ Form::text('name') }}
{{ Form::label('description', 'Company Description:', array('class' => 'col-sm-3')) }}
{{ Form::text('description') }}
{{ Form::label('industry', 'Industry', array('class' => 'col-sm-3')) }}
{{ Form::text('industry') }}
{{ Form::label('phone', 'Phone Number:', array('class' => 'col-sm-3')) }}
{{ Form::text('phone') }}
<p>{{ Form::submit('Sign in'); }}
{{ Form::close(); }}
#else
<p>just a test for New User Page
#endif
#stop
The create page so far just results in getting the #else condition back. ie: "just a test for New User Page"
Thanks in advance
i will avoid all your codes because you are making it way complicated than it is.
i will explain in step by step.
make two views. one for job seeker, one for employer.
depending upon the category, load the respective view. that's all you want.
let's come to code.
Routes.php
Route::get('create/{category}', array(
'as' => 'create',
'uses' => 'UserController#create'
));
UserController
public function create($category)
{
if($category==1)
return View::make('seeker');
elseif($category==2)
return View::make('employer');
else
App::abort(400);
}
that's it. no need to touch the layout. Avoid putting logics in layout as possible. in longer run, it will be a mess.