Skip to content

Commit

Permalink
Login and Registration Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Clark Chen committed Jun 11, 2014
1 parent 8bead74 commit 7c65beb
Show file tree
Hide file tree
Showing 36 changed files with 9,226 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/config/database.php
Expand Up @@ -55,9 +55,9 @@
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'database' => 'mabimart',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
Expand Down
10 changes: 5 additions & 5 deletions app/config/mail.php
Expand Up @@ -28,7 +28,7 @@
|
*/

'host' => 'smtp.mailgun.org',
'host' => 'localhost',

/*
|--------------------------------------------------------------------------
Expand All @@ -41,7 +41,7 @@
|
*/

'port' => 587,
'port' => 25,

/*
|--------------------------------------------------------------------------
Expand All @@ -54,7 +54,7 @@
|
*/

'from' => array('address' => null, 'name' => null),
'from' => array('address' => 'dev@mabimart.com', 'name' => 'Mabi Mart'),

/*
|--------------------------------------------------------------------------
Expand All @@ -80,7 +80,7 @@
|
*/

'username' => null,
'username' => 'dev@mabimart.com',

/*
|--------------------------------------------------------------------------
Expand All @@ -93,7 +93,7 @@
|
*/

'password' => null,
'password' => '!Ranger1024#',

/*
|--------------------------------------------------------------------------
Expand Down
120 changes: 120 additions & 0 deletions app/controllers/AccountController.php
@@ -0,0 +1,120 @@
<?php

class AccountController extends BaseController {

/*
|--------------------------------------------------------------------------
| Default Home Controller
|--------------------------------------------------------------------------
|
| You may wish to use controllers instead of, or in addition to, Closure
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
| Route::get('/', 'HomeController@showWelcome');
|
*/
protected $layout = 'layouts.master';
public function getActivate($code)
{
$user = User::where('activation_code', '=', $code)->where('active', '=', '0');

if($user->count()){
$user = $user->first();

$user->active = '1';
$user->activation_code = '';

if($user->save()) {
return Redirect::route('login')->with('success_message', 'Activated! You can sign in now :)');
}
}
return Redirect::route('login')->with('error_message', 'Something went wrong with your activation :(');
}
public function postLogin()
{
$validator = Validator::make(Input::all(),
array(
'email' => 'required|email',
'password' => 'required'
)
);
if($validator->fails()) {
return Redirect::route('login')
->withErrors($validator)
->withInput();
}
else {
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1)
);

if($auth) {
return Redirect::intended('/');
}
else {
return Redirect::route('login')->withInput()->with('error_message', 'Incorrect credentials or account not activated.');
}
}

return Redirect::route('login')
->with('error_message', 'There was a problem signing in.');
}

public function getLogin()
{
$this->layout->content = View::make('login');
}

public function getRegistration()
{
$this->layout->content = View::make('registration');
}
public function postRegistration()
{
$validator = Validator::make(Input::all(),
array(
'email' => 'required|max:254|email|unique:users',
'username' => 'required|max:30|min:3|unique:users',
'password' => 'required|min:8',
'confirmpassword' => 'required|same:password'
)
);
if($validator->fails()) {
return Redirect::route('register')
->withErrors($validator)
->withInput();
}
else {
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('password');

//Activation code generation
$activcode = str_random(60);

$user = User::create(array(
'email' => $email,
'username' => $username,
'password' => Hash::make($password),
'activation_code' => $activcode));

if($user) {

/*Mail::send('emails.auth.activate', array('link' => URL::route('activate', $activcode), 'username' => $username), function($message) use $user {
$message->to($user->email, $user->username)->subject('Activate your MabiMart Account');
});
return Redirect::route('login')->with('success_message', 'Your account has been created. Please visit your e-mail address and activate it.');*/

}
else {
Redirect::route('register')
->withInput();
}

}
}

}
47 changes: 47 additions & 0 deletions app/controllers/LoginController.php
@@ -0,0 +1,47 @@
<?php

class LoginController extends BaseController {

/*
|--------------------------------------------------------------------------
| Default Home Controller
|--------------------------------------------------------------------------
|
| You may wish to use controllers instead of, or in addition to, Closure
| based routes. That's great! Here is an example controller method to
| get you started. To route to this controller, just add the route:
|
| Route::get('/', 'HomeController@showWelcome');
|
*/
protected $layout = 'layouts.master';

public function get()
{
if (Auth::check()) {
return Redirect::intended('dashboard');
}
else {
$this->layout->content = View::make('login');
}
}
public function login()
{
if(Input::has('email') && Input::has('password')) {
$email = Input::get('email');
$password = Input::get('password');
$rememberme = Input::get('remember', false);
if (Auth::attempt(array('email' => $email, 'password' => $password), $rememberme))
{
return Redirect::intended('dashboard');
}
else {
$this->layout->content = View::make('login')->with('error', 'Incorrect e-mail address or password');
}

}
else {
$this->layout->content = View::make('login')->with('error', 'You did not specify an e-mail or password');
}
}
}
42 changes: 42 additions & 0 deletions app/database/migrations/2014_06_10_224409_create_users_table.php
@@ -0,0 +1,42 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');

$table->string('username',32);
$table->string('email', 320);
$table->string('password', 64);

$table->string('remember_token', 100)->nullable();

$table->string('activation_code', 60);
$table->boolean('active')->default(false);

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}

}
2 changes: 2 additions & 0 deletions app/models/User.php
Expand Up @@ -7,6 +7,8 @@

class User extends Eloquent implements UserInterface, RemindableInterface {

protected $fillable = array('email', 'username', 'password', 'active', 'activation_code');

use UserTrait, RemindableTrait;

/**
Expand Down
35 changes: 35 additions & 0 deletions app/routes.php
Expand Up @@ -15,3 +15,38 @@
{
return View::make('hello');
});

Route::group(array('before' => 'guest'), function() {
//CSRF protection
Route::group(array('before' => 'csrf'), function() {
//Registering
Route::post('/register', array(
'as' => 'register-post',
'uses' => 'AccountController@postRegistration')
);

//Signing In
Route::post('/login', array(
'as' => 'login-post',
'uses' => 'AccountController@postLogin')
);
});

//Signing In
Route::get('/login', array(
'as' => 'login',
'uses' => 'AccountController@getLogin')
);

//Registration
Route::get('/register', array(
'as' => 'register',
'uses' => 'AccountController@getRegistration')
);

//Activation
Route::get('/account/activate/{code}', array(
'as' => 'activate',
'uses' => 'AccountController@getActivate')
);
});
15 changes: 15 additions & 0 deletions app/views/emails/auth/activate.blade.php
@@ -0,0 +1,15 @@
Hiya {{ $username }}!

Thanks for registering for an account at MabiMart! All that's left is for you to activate your account.
<br>
Just visit the URL below to activate your account.<br>
---
{{ $link }}<br>
---
<br>
<br>
Remember, till then you won't be able to login to your account!

<br><br>
Thanks,<br>
- Rhaenyx (MabiMart creator)
53 changes: 53 additions & 0 deletions app/views/layouts/master.blade.php
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>MabiMart | @yield('page-title')</title>
<link href="css/bootstrap.min.css" rel="stylesheet">

<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div class="container" id="logoarea">
<div class="col-xs-2 col-md-2">
<img src="images/logo.png">
</div>
<!--<div class="col-xs-3 pull-right col-md-2 text-right" id="userpanel">
Welcome, <b>Guest</b>. </br> Please <a href="/login">Login</a> or <a href="/register">Register</a>.
</div>-->
</div>
<div class="navbar-inverse navbar-default" role="navigation" id="navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
@if(Auth::check())
<li>You successfully logged in.</li>
@else
<li><a href="{{ URL::route('login') }}">Login</a>
@endif

</ul>
</div>
</div>
</div>
<div class="container" id="content">
@yield('content')
<div id="footer" class="col-md-12 col-xs-12">
Copyright &copy; 2014 MabiMart. Built lovingly with <a href="http://getbootstrap.com/">Bootstrap</a>.
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

0 comments on commit 7c65beb

Please sign in to comment.