diff --git a/include/controllers/default/crunchbutton/api/user/index.php b/include/controllers/default/crunchbutton/api/user/index.php index a0236beb2..f7c1b730d 100644 --- a/include/controllers/default/crunchbutton/api/user/index.php +++ b/include/controllers/default/crunchbutton/api/user/index.php @@ -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; } diff --git a/include/crunchbutton.php b/include/crunchbutton.php index 594eaed8d..b689a48e1 100755 --- a/include/crunchbutton.php +++ b/include/crunchbutton.php @@ -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' => [ diff --git a/include/library/Crunchbutton/User.php b/include/library/Crunchbutton/User.php index 33122d47d..807bf179d 100644 --- a/include/library/Crunchbutton/User.php +++ b/include/library/Crunchbutton/User.php @@ -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(); } diff --git a/include/library/Crunchbutton/User/Auth.php b/include/library/Crunchbutton/User/Auth.php index b657b40bc..5dd04ee9b 100644 --- a/include/library/Crunchbutton/User/Auth.php +++ b/include/library/Crunchbutton/User/Auth.php @@ -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 diff --git a/include/library/Crunchbutton/User/Auth/Reset/Email.php b/include/library/Crunchbutton/User/Auth/Reset/Email.php new file mode 100644 index 000000000..58ab1c9d9 --- /dev/null +++ b/include/library/Crunchbutton/User/Auth/Reset/Email.php @@ -0,0 +1,23 @@ +'; + $params['reply'] = 'Tech Support '; + + $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); + } +} diff --git a/include/views/default/crunchbutton/layout/html.bottom.phtml b/include/views/default/crunchbutton/layout/html.bottom.phtml index 1423414e0..faaf9237e 100644 --- a/include/views/default/crunchbutton/layout/html.bottom.phtml +++ b/include/views/default/crunchbutton/layout/html.bottom.phtml @@ -24,6 +24,7 @@
+
diff --git a/www/assets/css/style.css b/www/assets/css/style.css index 888d582b0..cd1abbcd5 100644 --- a/www/assets/css/style.css +++ b/www/assets/css/style.css @@ -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; } diff --git a/www/assets/images/sign-up.png b/www/assets/images/sign-up.png new file mode 100644 index 000000000..5e3958144 Binary files /dev/null and b/www/assets/images/sign-up.png differ diff --git a/www/assets/js/app.js b/www/assets/js/app.js index dda20c978..dc2c2acd6 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -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 = $('
') - .append('
' + (App.config.user.phone ? App.phone.format(App.config.user.phone) : 'no phone # provied') + '
'); + + $('.payment-form').hide(); + + var dp = $('
'); + + dp.append('
' + (App.config.user.phone ? App.phone.format(App.config.user.phone) : 'no phone # provided') + '
'); var paying = $( '
' + @@ -348,11 +351,12 @@ App.page.restaurant = function(id) { '
'); dp.append(paying); + if (App.config.user.delivery_type == 'delivery' && App.restaurant.delivery == '1') { dp.append('

' + (App.config.user.address ? App.config.user.address.replace("\n",'
') : 'no address provided') + '
'); } else { dp.append('
takeout
'); - } + } dp.append('
Change delivery or payment details
'); @@ -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.' + 'Add a password now' ); $( '.signup-add-password-button' ).live( 'click', function(){ - App.signup.show(); + App.signup.show( false ); } ); }); }); @@ -659,17 +663,29 @@ App.page.orders = function() { }); } - var signout = '' + - '
' + - 'Sign out' + - '
'; - $( '.main-content-readable' ).append( signout ); - - if( !App.signoutBinded ){ + var signupFacebook = 'Connect with Facebook'; + if( App.signin.facebook.isLogged || App.config.user.facebook ){ + signupFacebook = ''; + } + + var bottomMenu = '
' + + signupFacebook + + 'Sign out' + + '
' + + '
'; + + $( '.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(){ '' + '
' + '
' + - 'Nevermind' + + 'Never mind' + 'Reset' + '
' + '' + @@ -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(){ '
' + '' + '
' + @@ -2895,10 +2921,10 @@ App.signup.html = function(){ ''; } -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 ); + } } } } );