Protect laravel routes with amember - php

I am using laravel for my web application. I have integrated amember within my larvel site inside /publi/amember. Now i want to protect my routes using amember. Anyone knows how to do it. I am using L5 Moduler structure for my larvel site.

The best approach is use Am_Lite API to do it.
http://www.amember.com/docs/API/Lite
So you need to include this file
amember/library/Am/Lite.php
within your application (before any output done) and then use the following call to check access:
Am_Lite::getInstance()->checkAccess(Am_Lite::PAID);
In event of user has necessary access then this call do nothing otherwise redirect user to login form.

Related

How do i share Laravel session with another PHP application?

I want to be able to share Laravel session with another PHP app(not Laravel), so i can redirect one app to another and still maintaining the same state. Both apps share the same database and i'm host the PHP app on a subdomain. How do i go about it. Thanks
You can define a POST route on another php app, and send credentials to it with curl for example.

TYPO3 a few questions about felogin

i would like to redirect to a page outside from the typo3. is this possible because i donĀ“t find a input form to do that?
I have an external PHP application. This application may only be called after a successful login. Is it possible to bind the login data from felogin to a session that I can use in my PHP application? I need the login information in my PHP application. I would like to use the felogin logout mechanism in my external PHP application. Is that possible?
Regards
MS-Tech
Not by default.
The easiest way I can think of, if the external PHP application runs on the same domain, is to alter the PHP application to read the TYPO3 frontend user cookie (fe_typo_user) and get session (fe_sessions table) and frontend user (fe_users table) data from the database.
The cleanest way I can think of is to rewrite the external PHP application as a TYPO3 extension, but I'm assuming this would be too much work.
As for the log out, you can link to the TYPO3 login page and add ?logintype=logout to the URL.

How to make web installer for my Laravel application?

I know of #RachidLaasri/LaravelInstaller but it is rather a kind of different thing I want.
I want to do something like, go to a URL like localhost::8000/installer. Then, it will display a page for super admin registration, i.e., email, password, and username. Note: I want to eliminate the ability of making my superadmin app user going to the UsersTableSeeder to configure anything.
Then, when I click on install, it migrate my seeded classes. I currently watched the command line app but still can't really figure out how to go about this.
Any advice / tip will be appreciated.
Laravel Installer
add 2 router in your project.
http :
routes.php
routes2.php
---
view
application/
installation/
in first route you should take db name and more information you need from user. Save db name to .evn file.
After then you might create database using php codes, How to make db Pdo
and run \Artisan::call('migrate') in your Controller.
Rename route to installation-route using php rename method file. And rename route2 to route.
Have you tried this PHP Application Installer
This library can be used for PHP appplication configuration(database, admin credentials etc) using user interface.

What does php middleware refers to?

Sorry if you are upset that this is not a very specific question but I researched online and couldn't find out what PHP middleware refers to?
I have seen this term used in the Slim microframework and laravel framework and I really need an explanation.
Thanks a lot
I'm no tremendous expert but i can try to explain it. Basically middleware in l5 and up replaces filters that were in place on older laravel versions. It adds verification to either a route/controller or the whole site. It will run whatever logic you have in a middleware before rendering a specific page to the user. For instance, laravel comes with an auth and csrf middleware upon installation. The auth middleware will check if the user is authenticated BEFORE showing a page and csrf verifies on everything and makes sure your current token matches what is present on the db.
To create a middleware you need to php artisan make:middleware NameofMiddleware.
A middleware can either be per each route or for the whole application.

Combining Angularjs and CodeIgniter

I am working on an existing site written in CodeIgniter and we are looking at using AngularJS for some pages that require a lot of frontend functionality but we don't want to replace all all CodeIgniter views (at once (yet)).
So i click a link that's controlled by angular's router and it is handled by javascript but next link could be a "normal" request that should handled by the CodeIgniter framework.
Is there some elegant way to combine these two methods? I don't really mind some extra client side overhead because the site is not running in production yet.
It sounds like you're looking to gradually make less use of CodeIgniter's (CI) routing as your angular application grows. This is not difficult but requires a lot of detail. Which method will work depends on your project structure. Note: I removed index.php from Code Igniter URLs, so the paths below may be different than default.
1) CodeIgniter installed in root
If CI is installed on the root of your server, you can create a folder within CI (for instance I have an "ng" folder). Your project will look like:
/controllers
/models
/ng
(etc)
/index.php (code igniter index file)
place an .htaccess file within /ng with the following:
Order allow, deny
Allow from all
This allows the files within /ng to be directly accessed, rather than sending those requests back through CI's routing system. For example you can load this directly now:
example.com/ng/partials/angular-view.html
The main web page will still be created by CodeIgniter, but it can now include Angular assets, such as partial views, etc. Eventually you can replace most of what CodeIgniter is doing by just returning a simple page, and having Angular load partial views from /ng like it's designed for.
This method is nice because CodeIgniter can control whether that initial page is loaded at all (via some user authentication code in your CI controller). If user isn't logged in, they are redirected and never see the Angular app.
2) CodeIgniter in Directory
If CI is installed in a directory, such as example.com/myapp/(code igniter) you can simply create a directory next to it, example.com/myappNg/
/myapp/
/myapp/controllers/
/myapp/models/
/myapp/(etc)
/myapp/index.php (code igniter index file)
/myappNg/
/myappNg/partials/
/myappNg/js/
/myappNg/(etc)
Now in your Angular application, you can request resources from CI by making paths relative to the domain root, rather than relative to the Angular app. For instance, in Angular, you will no longer request a partial view from the Angular folder partials/angular-view.html, rather you'll want to request views from CI /myapp/someResource. Note the leading /. "someResource" can return an html document, or JSON or whatever you're doing with Code Igniter in the first place.
Eventually you can replace the number of paths which reference /myapp/. Once you no longer use CI for anything, you can simply place your Angular index.html in /myapp/ and it will continue to reference your paths at /myappNg/.
TL;DR Make your Angular app fully available and decouple it from CodeIgniter. Gradually move toward using Angular partial views and other JSON sources instead of linking to CodeIgniter pages. Eventually replace your CodeIgniter endpoint with an HTML file which bootstraps Angular.
Your best bet is to keep your backend code separate from the angular code
and use the codeInginter code as an API
/Codeigniter Code
/Angular Code
Because CodeIgniter comes with its share of security feature this should be your best bet
I've never used Angular - nevertheless this may help.
So i click a link that's controlled by angular's router and it is
handled by javascript
Does this JavaScript make an Ajax request to one of your CI's controllers? If so, CI now has the is_ajax_request() method, which allows you to check if a request (POST or GET) is coming via ajax. You can proceed differently based on a request coming from Ajax vs a normal request.
User guide (bottom of the page): http://ellislab.com/codeigniter/user-guide/libraries/input.html
Hope it helps!
I inherited a CI app and I'm using Angular with CI mainly for routing requests. In my case I am not using Angular templates, so I use a ' ' empty but with a space parameter for the template option in my $routeProvider config. This allows me to do the usual CI ajax requests without too much change to the original server-side code.
angular.module('my_app', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', { template: " ", controller: my_routes.mainpage}).
when('/design/:designId/:action', {template: " ", controller: my_routes.show_design}).
when('/vote_design/:designId', {template: " ", controller: my_routes.vote_design}).
otherwise({redirectTo: '/'});
}]);
To addition to the answer given by Aaron Martin, one can also use it as a client - server approach.
Lets say we make 2 folders in root of our project :
Client
Server
Client folder will contain all the code of AngularJS and the client side libraries including the Bower and Npm libraries.
The routing of the client side will also be handled by AngularJS router.
There will be factories or services which will act as providers for angularjs on client side.
Those file will contain the code of sending request and receiving response from server side.
Server Folder will have the code of Laravel or CodeIgniter or Any other PHP framework.
You will create all the APIs of the requests and develop the functionality accordingly.
Hence the PHP section (Server Directory) at the whole will be storing all the Media Files and Database Files. Moreover it will also have any receiving links for RSS feeds and so on.
The Client shall just receive all the response in JSON or XML format when it requests on any API on its server..
This according to me is one of the finest practice for developing Webapps.
I picked up a CI site from another programmer I work with that is on leave for a few months. Our site is build mostly with a lot of angular due to the the nature of its purpose. Our solution was a little different.
All that varies from the standard CI framework is a couple folders: js\angular\controllers andjs\angular\modules in CI's application folder, to hold all of the angular model and controller files. Then load the angular docs into the application base folder.

Categories