This commit is contained in:
Stuardo Rodríguez 2013-02-06 15:22:10 -05:00
commit 61b06a1b03
9 changed files with 174 additions and 47 deletions

View File

@ -69,13 +69,27 @@ class Controller_api_user extends Crunchbutton_Controller_Rest {
echo json_encode(['error' => 'user exists']);
exit;
}
$user = c::user();
if (!$user->id_user) {
// we dont have a user, and we need to make one
$user = new User;
$user->active = 1;
if( filter_var( $_POST[ 'email' ], FILTER_VALIDATE_EMAIL ) ){
$user->email = $_POST[ 'email' ];
} else {
$user->phone = $_POST[ 'email' ];
}
$user->name = '';
$user->save();
}
$user_auth = new User_Auth();
$user_auth->id_user = c::user()->id_user;
$user_auth->id_user = $user->id_user;
$user_auth->type = 'local';
$user_auth->auth = User_Auth::passwordEncrypt( $params[ 'password' ] );
$user_auth->email = $params[ 'email' ];
$user_auth->active = 1;
$user_auth->save();
$user = c::auth()->doAuthByLocalUser( $params );
echo c::user()->json();
break;
}

View File

@ -12,7 +12,7 @@
// keep the directory setup in here so we can change its path later
set_include_path(get_include_path() . PATH_SEPARATOR . '/Users/arzynik/pear/share/pear');
set_include_path(get_include_path() . PATH_SEPARATOR . '/Users/pererinha/pear/share/pear');
$GLOBALS['config'] = [
'dirs' => [

View File

@ -50,6 +50,7 @@ class Crunchbutton_User extends Cana_Table {
public function exports() {
$out = $this->properties();
$out[ 'last_tip' ] = Order::lastTip( $this->id_user );
$out[ 'facebook' ] = User_Auth::userHasFacebookAuth( $this->id_user );
foreach ($this->presets() as $preset) {
$out['presets'][$preset->id_restaurant] = $preset->exports();
}

View File

@ -66,14 +66,14 @@ class Crunchbutton_User_Auth extends Cana_Table {
}
return $auths;
}
public function user() {
if (!isset($this->_user)) {
return new Crunchbutton_User($this->id_user);
}
return $this->_user;
}
public function checkEmailExists( $email ){
$row = Cana::db()->get('
SELECT *
@ -89,6 +89,22 @@ class Crunchbutton_User_Auth extends Cana_Table {
return false;
}
public function userHasFacebookAuth( $id_user ){
$row = Cana::db()->get('
SELECT *
FROM user_auth
WHERE
id_user="' . $id_user . '"
AND type = "facebook"
AND active=1
');
if( $row->_items && $row->_items[0] ){
$row = $row->_items[0];
return true;
}
return false;
}
public function validateResetCode( $code ){
$query = sprintf(" SELECT *
FROM user_auth

View File

@ -0,0 +1,23 @@
<?php
class Crunchbutton_User_Auth_Reset_Email extends Crunchbutton_Email {
private $_mailConfig;
public function __construct($params) {
$params['to'] = $params['email'];
$params['subject'] = 'Customer Password reset';
$params['from'] = '<tech@_DOMAIN_>';
$params['reply'] = 'Tech Support <tech@_DOMAIN_>';
$this->buildView($params);
$this->view()->subject = $params['subject'];
$this->view()->email = $params['email'];
$this->view()->message = $params['message'];
$params['messageHtml'] = $this->view()->render('order/index',['display' => true, 'set' => ['order' => $params['order']]]);
parent::__construct($params);
}
}

View File

@ -24,6 +24,7 @@
<div class="signin-box-header">
<div class="signin-user"></div>
<div class="signin-icon"></div>
<div class="signup-icon"></div>
<!-- <div class="signout-icon"></div> -->
</div>
</div>

View File

@ -770,19 +770,20 @@ html[xmlns] .clearfix {
.sign-in-icon{
display: none;
}
.signout-container{
display: block;
margin: 10px;
text-align: center;
.order-options{
border-top: 1px solid #F5F5F5;
margin-top: 10px;
padding: 10px;
}
.signout-button{
.signout-button, .signup-add-facebook-button{
border-radius: 4px;
border: 1px solid #cb5921;
padding: 6px 10px 6px 12px;
color: #fff;
display: block !important;
float: left;
display: block inline !important;
width: 60px;
margin: 10px auto;
margin:0 10px 10px 0;
text-decoration: none;
text-align: center;
text-shadow: 1px 1px 0px rgba(0,0,0,.22);
@ -795,7 +796,13 @@ html[xmlns] .clearfix {
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#f57333', endColorstr='#f26926')";
background: linear-gradient(#f57333, #f26926);
}
.signup-add-facebook-button{
width: 190px;
}
.config-icon-desktop-hide{
display: none;
}
.logo {
float: left;
@ -1427,6 +1434,9 @@ html[xmlns] .clearfix {
.config-icon-mobile-hide{
display: none;
}
.config-icon-desktop-hide{
display: block;
}
.config-icon {
float: left;
}
@ -1789,11 +1799,16 @@ html[xmlns] .clearfix {
float: right;
height: 30px;
margin: 12px 0 0 10px;
width: 215px;
}
.signin-box-header-min{
width: 60px;
}
.signin-icon {
background: url(/assets/images/sign-in.png) no-repeat;
background-size: contain;
cursor: pointer;
float: right;
display: none;
height: 30px;
width: 98px;
@ -1803,17 +1818,37 @@ html[xmlns] .clearfix {
background-size: contain;
cursor: pointer;
display: none;
float: right;
height: 30px;
width: 110px;
}
.signup-icon {
background: url(/assets/images/sign-up.png) no-repeat;
background-size: contain;
cursor: pointer;
float: left;
display: none;
height: 30px;
width: 103px;
}
.signin-user{
background: url(/assets/images/sign-in-icon.png) no-repeat;
background-size: contain;
cursor: pointer;
float: right;
display: none;
height: 30px;
width: 45px;
/*
color: #FFF;
cursor: pointer;
display: none;
margin-top: 8px;
text-align: center;
text-shadow: 1px 1px 0px rgba(0,0,0,.22);
*/
}
.signup-success-container{
display: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -332,12 +332,15 @@ App.page.restaurant = function(id) {
App.cart.loadOrder(App.restaurant.preset());
}
if (App.config.user.id_user) {
if (App.config.user.presets) {
App.drawPay(this);
$('.payment-form').hide();
var dp = $('<div class="delivery-payment-info main-content-readable"></div>')
.append('<div class="dp-display-phone dp-display-item"><label>Your phone number:</label> ' + (App.config.user.phone ? App.phone.format(App.config.user.phone) : '<i>no phone # provied</i>') + '</div>');
$('.payment-form').hide();
var dp = $('<div class="delivery-payment-info main-content-readable"></div>');
dp.append('<div class="dp-display-phone dp-display-item"><label>Your phone number:</label> ' + (App.config.user.phone ? App.phone.format(App.config.user.phone) : '<i>no phone # provided</i>') + '</div>');
var paying = $(
'<div class="dp-display-payment dp-display-item ">' +
@ -348,11 +351,12 @@ App.page.restaurant = function(id) {
'</div>');
dp.append(paying);
if (App.config.user.delivery_type == 'delivery' && App.restaurant.delivery == '1') {
dp.append('<div class="dp-display-address dp-display-item"><label>Your food will be delivered to:</label><br />' + (App.config.user.address ? App.config.user.address.replace("\n",'<br />') : '<i>no address provided</i>') + '</div>');
} else {
dp.append('<div class="dp-display-address dp-display-item"><label>Address:</label> <i>takeout</i></div>');
}
}
dp.append('<div class="dp-display-address dp-display-item"><a href="javascript:;"><i>Change delivery or payment details</i></a></div>');
@ -594,7 +598,7 @@ App.page.order = function(id) {
$('.signup-call-to-action').html( 'If you added a password, you can place 1 click orders at crunchbutton.com on your phone too.' +
'<a href="javascript:;" class="signup-add-password-button">Add a password now</a>' );
$( '.signup-add-password-button' ).live( 'click', function(){
App.signup.show();
App.signup.show( false );
} );
});
});
@ -659,17 +663,29 @@ App.page.orders = function() {
});
}
var signout = '' +
'<div class="signout-container">' +
'<a href="javascript:;" class="signout-button">Sign out</a>' +
'</div>';
$( '.main-content-readable' ).append( signout );
if( !App.signoutBinded ){
var signupFacebook = '<a href="javascript:;" class="signup-add-facebook-button">Connect with Facebook</a>';
if( App.signin.facebook.isLogged || App.config.user.facebook ){
signupFacebook = '';
}
var bottomMenu = '<div class="order-options">' +
signupFacebook +
'<a href="javascript:;" class="signout-button">Sign out</a>' +
'<div class="divider"></div>' +
'</div>';
$( '.main-content-readable' ).append( bottomMenu );
if( !App.bottomMenuBinded ){
$( '.signout-button' ).live( 'click', function(){
App.signin.signOut();
} );
App.signoutBinded = true;
$( '.signup-add-facebook-button' ).live( 'click', function(){
App.signup.show( true );
} );
App.bottomMenuBinded = true;
}
App.refreshLayout();
@ -2460,7 +2476,7 @@ App.signin.html = function(){
'<input type="text" maxlength="250" name="password-help-email" placeholder="email or phone" tabindex="10" />' +
'<div class="divider"></div>' +
'<div class="password-help-error"></div>' +
'<a href="javascript:;" class="signin-password-help-back">Nevermind</a>' +
'<a href="javascript:;" class="signin-password-help-back">Never mind</a>' +
'<a href="javascript:;" class="signin-password-help-button">Reset</a>' +
'<div class="divider"></div>' +
'</form>' +
@ -2502,7 +2518,7 @@ App.signin.sendForm = function(){
data: { 'email' : email, 'password' : password },
dataType: 'json',
success: function( json ){
if( data.error ){
if( json.error ){
$('.signin-error').fadeIn();
} else{
App.config.user = json;
@ -2574,6 +2590,9 @@ App.signin.facebook.processStatus = function( session ){
if( App.currentPage == 'restaurant' && App.restaurant.permalink ){
App.page.restaurant( App.restaurant.permalink );
}
if( App.currentPage == 'orders' ){
App.page.orders()
}
}
} );
}
@ -2590,11 +2609,11 @@ App.signin.show = function(){
App.signin.passwordHelp.hide();
$( '.signin-facebook-message' ).hide();
$( '.signin-facebook' ).show();
if( App.signin.facebook.isLogged ){
/* if( App.signin.facebook.isLogged ){
$( '.signin-facebook-container' ).hide();
} else {
$( '.signin-facebook-container' ).show();
}
} */
setTimeout( function(){
/* Shows the shield */
App.modal.shield.show();
@ -2614,21 +2633,23 @@ App.signin.show = function(){
App.signin.checkUser = function(){
// If the user is logged
if( App.config.user.id_user ){
// If the user is at the order page show the sign-out button
/* if( App.currentPage == 'orders' ){
$( '.signin-user' ).hide();
$( '.signin-icon' ).hide();
$( '.signout-icon' ).show();
} else { */
$( '.signin-user' ).html( 'Hi, ' + App.config.user.name );
$( '.signin-user' ).show();
$( '.signin-icon' ).hide();
$( '.signout-icon' ).hide();
// }
// $( '.signin-user' ).html( 'Hi, ' + App.config.user.name );
$( '.signin-user' ).show();
$( '.signin-icon' ).hide();
$( '.signout-icon' ).hide();
$( '.signup-icon' ).hide();
$( '.signin-box-header' ).addClass( 'signin-box-header-min' );
} else {
$( '.signin-user' ).hide();
$( '.signin-icon' ).show();
$( '.signup-icon' ).show();
$( '.signout-icon' ).hide();
$( '.signin-box-header' ).removeClass( 'signin-box-header-min' );
}
if( App.currentPage == 'home' ){
$( '.config-icon' ).addClass( 'config-icon-desktop-hide' );
} else {
$( '.config-icon' ).removeClass( 'config-icon-desktop-hide' );
}
}
@ -2839,10 +2860,15 @@ App.signin.passwordHelp.reset.html = function( path ){
* Signup's methods
**************************/
App.signup = {};
App.signup.init = function(){
$( '.wrapper' ).append( App.signup.html() );
$( '.signup-icon' ).live( 'click', function(){
App.signup.show( false );
} );
$( '.signup-form-button' ).live( 'click', function(){
App.signup.sendForm();
} );
@ -2876,7 +2902,7 @@ App.signup.html = function(){
'<div class="signup-facebook">' +
'<a href="javascript:;" class="signup-facebook-button">' +
'<span class="signup-facebook-icon"></span>' +
'<span class="signup-facebook-text">Login with Facebook</span>' +
'<span class="signup-facebook-text">Signup with Facebook</span>' +
'<div class="divider"></div>' +
'</a>' +
'</div>' +
@ -2895,10 +2921,10 @@ App.signup.html = function(){
'</div>';
}
App.signup.show = function(){
App.signup.show = function( justFacebook ){
$( '.signup-facebook' ).show();
$( '.signup-facebook-message' ).hide();
if( App.signin.facebook.isLogged ){
if( App.config.user.facebook ){
$( '.signup-facebook-container' ).hide();
} else {
$( '.signup-facebook-container' ).show();
@ -2910,6 +2936,11 @@ App.signup.show = function(){
$( 'input[name=signup-password]' ).val( '' );
$( '.signup-form-options' ).show();
$( '.signup-success-container' ).hide();
if( justFacebook ){
$( '.signup-form' ).hide();
} else {
$( '.signup-form' ).show();
}
$( '.signin-error' ).hide();
$( '.signup-container' )
.dialog( {
@ -2973,17 +3004,23 @@ App.signup.sendForm = function(){
url: url,
data: { 'email' : login, 'password' : password },
dataType: 'json',
success: function( data ){
if( data.error ){
if( data.error == 'user exists' ){
success: function( json ){
if( json.error ){
if( json.error == 'user exists' ){
$('.signup-error').html( 'It seems that the email/phone that is already registered!' );
}
$('.signup-error').fadeIn();
} else{
App.config.user = json;
$( '.success-phone' ).html( login );
$( '.signup-call-to-action' ).hide();
$( '.signup-form-options' ).hide();
$( '.signup-success-container' ).show();
App.signin.checkUser();
// If the user is at the restaurant's page - reload it
if( App.currentPage == 'restaurant' && App.restaurant.permalink ){
App.page.restaurant( App.restaurant.permalink );
}
}
}
} );