Skip to content

Instantly share code, notes, and snippets.

@tessguefen
Created August 11, 2016 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tessguefen/c1514f7ac64b74438e5fbcbfcff6d9b4 to your computer and use it in GitHub Desktop.
Save tessguefen/c1514f7ac64b74438e5fbcbfcff6d9b4 to your computer and use it in GitHub Desktop.
Google OAuth
<!DOCTYPE html>
<html>
<head>
<title>Google+ Login</title>
<mvt:item name="oauth-js" />
<mvt:item name="oauth-css" />
</head>
<body>
</head>
<body>
<div class="log_container"><br/>
<div id="login-form" >
<div id="name" class="line-break"></div>
<div class="jointext">I don't, but I'd sure like one.</div>
<a href="#" onClick="$.fn.create( data );" class="btn clear">Create My Account!</a>
<div id="enter-password"><a href="#" onClick="$.fn.prompt_password( data )">Create Account, but allow me to choose a password first</a></div>
<div class="spacer">
<div class="line-break-mid"></div>
<div class="spacerText">or</div>
<div class="line-break-mid"></div>
</div>
<div class="clear"></div>
<div id="sign_up">
<div class="content"> <b class="signintext">Already Have an Account at &mvte:store:name;?</b><br/>
<h3>If you have an existing account, just sign in to link your account with facebook</h3>
<form id="logn" action="&mvt:global:secure_sessionurl" method="post" autocomplete="off" onSubmit="$.fn.miva_login( data ); return false;">
<div id="signup-logn-email">
<label>Email:</label> <input type="text" name="Customer_LoginEmail" id="Customer_LoginEmail" class="textfield logn-input" value="&mvte:global:Customer_LoginEmail;" autocomplete="off" />
</div>
<div id="signup-logn-password">
<label>Password:</label> <input type="password" name="Customer_Password" id="Customer_Password" class="textfield logn-input" autocomplete="off" />
</div>
<div class="signup-logn-submit">
<input type="submit" name="Name" value="Sign In" class="btn"/>
</div>
</form>
<div id="status-message"></div>
<div class="clear"></div>
</div>
</div>
</div>
<!-- Progress Bar Div-->
<div id="progress-bar">
<h3 id="success-message">You are now logged in.</h3>
<img src="/images/ring-alt.gif" alt="Loading" title="Loading">
</div>
<!-- Password Prompt Div -->
<div id="password-prompt">
<h3>Last Step! Would you like to create a password?</h3>
<div id="sub-text">This allows you to login using your email address and password in addition to facebook. </div>
<form id="password" action="&mvt:global:secure_sessionurl" method="post" autocomplete="off" onSubmit="$.fn.create( data ); return false;">
<div id="password-prompt-login">
Email: <input type="text" name="Customer_LoginEmail" id="Change_Customer_LoginEmail" class="textfield logn-input" value="&mvte:global:Customer_LoginEmail;" autocomplete="off" />
</div>
<div id="password-prompt-password">
Password: <input type="password" name="Customer_Password" id="Change_Customer_Password" class="textfield logn-input" autocomplete="off" />
</div>
<div class="password-submit-btn">
<input type="submit" name="Name" value="Complete Signup" class="btn"/>
</div>
</form>
</div>
</div>
</body>
</html>
<mvt:comment>Used for google login AJAX Call</mvt:comment>
<mvt:if expr="g.basket:cust_id NE 0">
<!-- LOGN:1 -->
<mvt:else>
<!-- LOGN:0 -->
</mvt:if>
<!--[if IE 7]>
<style type="text/css">
.spacerText {line-height:8px;}
#sign_up .content {padding-left:12px !important;}
#sign_up {margin-top:12px;}
#login-form .spacer { margin-top:12px; }
#status-message { right: 49px; top: 214px; }
</style>
<![endif]-->
<style type="text/css">
.log_container {
display:block;
width:680px;
height:auto !important;
height:320px;
min-height:320px;
border:2px solid #999;
color:#777;
text-align:center;
border-radius:4px;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
margin:0 auto;
padding-bottom:15px;
}
.line-break {
border-bottom:solid 1px #f1f1f1;
display:block;
width:90%;
margin:0 auto;
}
.line-break-mid {
border-bottom:solid 1px #f1f1f1;
display:block;
width:40%;
float:left;
margin-left:30px;
margin-right:30px;
}
input {
padding:7px 0px 7px 7px;
}
.btn {
-moz-box-shadow:inset 0 1px 0 0 #cae3fc;
-webkit-box-shadow:inset 0 1px 0 0 #cae3fc;
box-shadow:inset 0 1px 0 0 #cae3fc;
background:0;
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff',endColorstr='#4197ee');
background-color:#79bbff;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #469df5;
display:inline-block;
color:#fff;
font-family:arial;
font-size:15px;
font-weight:700;
cursor:pointer;
text-decoration:none;
text-shadow:1px 1px 0 #287ace;
padding:6px 24px;
}
.btn:hover {
background:0;
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#4197ee',endColorstr='#79bbff');
background-color:#4197ee;
cursor:pointer;
}
.btn:active {
position:relative;
top:1px;
}
.headtext {
font-size:17px;
width:540px;
margin-left:86px;
}
#sign_up {
text-align:left;
display:block;
width:90%;
height:auto !important;
height:80px;
min-height:80px;
border-radius:7px;
border:#ccc solid 1px;
background-color:#f6f6f6;
margin:0 auto;
margin-top: 15px;
padding:12px 12px 0px 12px;
}
#sign_up .content {
padding-left:20px;
}
#sign_up .content h3 {
color: #666666;
font-size: 12px;
font-weight: 100;
margin: 0;
}
#signup-logn-email {
float:left;
padding:10px 10px 10px 0px;
}
#signup-logn-password {
float:left;
padding:10px 10px 10px 0px;
}
.signup-logn-submit {
float:left;
padding:10px 0px 10px 10px;
}
#sign_up label {
vertical-align: middle;
}
#sign_up input {
vertical-align: middle;
}
#status-message {
color:red;
position: absolute;
right: 153px;
top: 202px;
}
#sub-text {
font-size:12px;
font-style:italic;
}
#picture {
position:absolute;
left:25px;
top:-7px;
border:2px solid #CCC;
}
#enter-password{
padding-top:8px;
}
#enter-password a {
font-size:11px;
color:#999;
font-style:italic;
}
#login-form {
width:100%;
position:relative;
display:none;
}
.clear {
clear:both;
}
.signintext,.jointext {
font-size:14px;
}
.jointext{
padding-bottom:10px;
padding-top:10px;
font-weight:bold;
}
.signintext {
padding-right: 8px;
}
.left {
float:left;
}
#login-form {
}
#login-form .spacer {
height:22px;
line-height:0px;
margin-top:32px;
}
#login-form .spacerText {
float:left;
}
#password-prompt {
display:none;
margin:auto;
width:600px
}
#password-prompt-login {
float:left;
padding:10px 10px 10px 60px;
}
#password-prompt-password {
float:left; padding:10px;
}
.password-submit-btn {
float:right;
padding:10px 75px 10px 10px;
}
#progress-bar {
display:none;
margin:auto;
width:300px;
margin-top:100px;
}
#name{
font-size: 15px;
padding-bottom: 10px;
}
</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready( function(){
if (window.opener.document.URL.indexOf("LOGN") == -1 ){
var return_url = '&mvt:global:secure_sessionurl;Screen=OCST&Store_Code=&mvte:store:code;';
}else{
var return_url = '&mvt:global:secure_sessionurl;&Screen=ACLN&Store_Code=&mvte:store:code;';
}
<mvt:if expr = "NOT g.Basket:cust_id">
$.ajax({
url: 'https://www.googleapis.com/plus/v1/people/me?access_token=&mvta:oauth:Google;&Session_Id=&mvte:global:session_id;',
type: 'GET',
dataType: 'json',
data: '',
success: function( response ) {
data = response;
$.fn.login( response );
},
error : function() {
alert( 'Error Authorizing User' );
return
}
});
$.fn.login = function( data )
{
$.ajax( {
url: '&mvt:global:json_url;Function=Module&Module_Function=OAuth_Login&Module_Code=oauth&Store_Code=&mvte:store:code;&Session_Type=runtime&Session_Id=&mvte:global:session_id;',
type: 'POST',
dataType: 'json',
data: 'Code=google&Access_Token=&mvta:oauth:google;&OAuth_ID=' + data.id,
success: function( response )
{
if ( !response.success )
{
if ( response.error_code == 'invalid_customer' )
{
var store_name = escape("&mvte:store:name;");
$('#name').html('Welcome ' + data.name.givenName + '! Do you already have existing account at ' + unescape(store_name) + '?');
$('#login-form').show();
} else {
return alert( response.error_message );
}
} else {
window.opener.document.location = return_url;
//change screen
$('#login-form').hide();
$('#password-prompt').hide();
$("#progress-bar").show();
setTimeout(
function()
{
window.close();
}, 3000);
}
}
} );
}
$.fn.prompt_password = function( data )
{
$('#login-form').hide();
$('#password-prompt').show();
$('#Change_Customer_LoginEmail').val( data.emails[0].value );
}
$.fn.create = function( data )
{
//change screen
$('#login-form').hide();
$('#password-prompt').hide();
$("#progress-bar").show();
//get email address and password from customer
customer_email = $('#Change_Customer_LoginEmail').val();
user_supplied_password = $('#Change_Customer_Password').val();
if(customer_email == ""){
customer_email = data.email;
}
$.ajax( {
url: '&mvt:global:json_url;Function=Module&Module_Function=OAuthCustomer_Create&Module_Code=oauth&Store_Code=&mvte:store:code;&Session_Type=runtime&Session_Id=&mvte:global:session_id;',
type: 'POST',
dataType: 'json',
data: 'Code=google' +
'&OAuth_ID=' + data.id +
'&Access_Token=&mvta:oauth:google;' +
'&Customer_ShipFirstName=' + data.name.givenName +
'&Customer_ShipLastName=' + data.name.familyName +
'&Customer_ShipEmail=' + data.emails[0].value +
'&Customer_BillFirstName=' + data.name.givenName +
'&Customer_BillLastName=' + data.name.familyName +
'&Customer_BillEmail=' + data.emails[0].value +
'&Customer_PasswordEmail=' + data.emails[0].value +
'&Customer_Password=' + user_supplied_password,
success: function( response )
{
if ( !response.success )
{
return alert( response.error_message );
}
$.fn.login( data );
}
} );
}
$.fn.miva_login = function( data )
{
var username = $("#Customer_LoginEmail");
var password = $("#Customer_Password");
$.ajax( {
url: '&mvt:global:secure_sessionurl;Action=LOGN&Store_Code=&mvte:store:code;&Screen=google-redirect&Session_Id=&mvte:global:session_id;',
type: 'POST',
dataType: 'html',
data: '&Customer_LoginEmail=' + username.val() +
'&Customer_Password=' + password.val(),
success: function( response )
{
if (response.indexOf("LOGN:1") == -1 ){
$("#status-message").html("Incorrect login. Please try again.");
username.val("");
password.val("");
}else{
window.opener.document.location = return_url;
$("#status-message").html("Login Successful");
$.fn.createAssociation(data.id)
}
}
} );
}
$.fn.createAssociation = function( oauth_id )
{
$.ajax( {
url: '&mvt:global:json_url;Function=Module&Module_Function=OAuthCustomer_Create_Association&Module_Code=oauth&Store_Code=&mvte:store:code;&Session_Type=runtime&Session_Id=&mvte:global:session_id;',
type: 'POST',
dataType: 'json',
data: 'Code=google&Access_Token=&mvta:oauth:google;&OAuth_ID=' + oauth_id,
success: function( response )
{
if ( !response.success )
{
return alert( response.error_message );
}
$('#login-form').hide();
$('#name').hide();
$('#success-message').html("Linking Facebook to your existing account.")
$("#progress-bar").show();
setTimeout(
function()
{
window.close();
}, 3000);
}
} );
}
<mvt:else>
window.opener.document.location = return_url;
window.close();
</mvt:if>
} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment