<commit_before><link rel="import" href="../../vendor/polymer/polymer.html">
<link rel="import" href="../../vendor/paper-button/paper-button.html">
<link rel="import" href="../../vendor/iron-icon/iron-icon.html">
<link rel="import" href="../../vendor/firebase-element/firebase-auth.html">

<dom-module id="fb-login">
	<template>
		<style>
			/* FIXME : use custom variable to change properties */
			:host {
				display: inline-block;
				@apply(--fb-login-container-theme);
			}

			:host paper-button {
				/*Shadow properties*/
				color: 				var(--fb-login-color, #FFFFFF);
				background-color: 	var(--fb-login-bg-color, #3B579D);
				font-weight:		var(--fb-login-fw, bold);				
			}

			paper-button {
				/*Mixin to define custom theme*/
				@apply(--fb-login-theme);
			}

			.icon {
			    --iron-icon-height: 32px;
			    --iron-icon-width: 32px;
			}
		</style>
		<iron-localstorage id="ls" name="app-storage" value="{{storage}}"
			on-iron-localstorage-load-empty="_initLocalStorage"></iron-localstorage>
		<firebase-auth id="auth"
					   location="[[_location]]"
					   on-location-changed="plop"
					   provider="facebook"
					   user="{{fireUser}}"
					   ref="{{ref}}">
		</firebase-auth>
		<paper-button id="loginButton" raised
					  on-tap="login">
			<iron-icon class="icon" src="../../img/FB-f-Logo__blue_50.png"></iron-icon>
			Login
		</paper-button>
	</template>
	<script>
		Polymer({
			is: 'fb-login',
			properties: {
				// Determine if the login action is automatically call
				// NOTE : If declared the test is true
				autoLogin: {
					type: Boolean,
					value: false,
					reflectToAttribute: true
				},
				apiLoaded: {
					type: Boolean,
					value: false,
					observer: '_apiObserver'
				},
				// Graph API URL to call to get data
				graphUrl: {
					type: String,
					value: ""
				},
				// Scope param of permission to ask for
				scope: {
					type: String,
					value: "public_profile"
				},
				// Graph API Response Object
				response: {
					type: Object,
					notify: true
				},
				fireUser: {
					notify: true,
					observer: '_fireUserchanded'
				},
				ref: {
					notify: true
				},
				// Local storage
				storage: {
					type: Object,
					notify: true
				}
			},
			checkLoginStatus: function () {
				var fbLogin = this;
				FB.getLoginStatus(function(response) {
					// Check login status on load, and if the user is already logged in
					if (response.status == 'connected') {
						console.info('Facebook account connected !');
						fbLogin._customLoginAction('connected', {user: fbLogin.fireUser});
					} else if (fbLogin.autoLogin) {
						// Otherwise, show Login dialog first.
						console.info('Facebook account not connected !');
						console.info('Auto login into Facebook !');
						fbLogin.login();
					} else {
						console.info('Facebook account not connected !');
						// Cleanup localstorage access_token
						if (fbLogin.storage.access_token) {
							fbLogin._setAccessToken("");
						}

						fbLogin.$.auth.addEventListener('login', function (e) {
							console.info('Login success into Firebase');
							fbLogin._customLoginAction('connected', e.detail);
						});

						fbLogin.fire('fb-not-connected');
					}
				});
			},
			login: function () {
				var fbLogin = this;

				// Get the connection with the provided scope
				this.scope = this.scope;
				this.$.auth.login({scope: this.scope});
			},
			_locationChanged: function (location) {
				console.log(location);
			},
			_apiObserver: function  (n, o) {
				var fbLogin = this;
				if (n) {
					console.info('Fb API is ready !');

					fbLogin.$.ls.reload()
					fbLogin._location = fbLogin.storage.firebase;

					console.info('Firebase connection established !');

					// Check if the user is actualy connected
					this.checkLoginStatus();

					// bind event to the error login action
					this.$.auth.addEventListener('error', function (e) {
						console.info('Login error into Facebook');
						fbLogin._customLoginAction('false', e.detail);
					});
				}
			},
			_customLoginAction: function (response, param) {
				param = (typeof param !== 'undefined')? param : {};

				var fbLogin = this;
				if (response == 'connected') {

					var access_token = param.user.facebook.accessToken;

					fbLogin._setAccessToken(access_token);

					FB.api(
						'/' + fbLogin.graphUrl,
						{access_token: access_token},
						function(data) {
							fbLogin.response 	= data;
							fbLogin.style.display = 'none';

							// Get the user picture and update the data object
							FB.api(
								"/me/picture",
								{access_token: access_token},
								function (response) {
									if (response && !response.error) {
										var data = fbLogin.response;
											data['picture'] = response;
										fbLogin.response = {};
										fbLogin.response = data;

										console.info('Login success into Facebook');
										fbLogin.fire('fb-login-success', param);
									}
								}
							);
					});
				} else {
					fbLogin.fire('fb-login-canceled', param);
				}
			},
			_initLocalStorage: function () {
				this.storage = {};
			},
			_fireUserchanded: function (fireUser) {
				if (fireUser) {
					console.info("Firebase access granted !");
				}
			},
			_setAccessToken: function (token) {
				var _at = {'access_token': token};
				var tmp = Object.assign(this.storage, _at);
				this.set('storage', {});
				this.set('storage', tmp);
			}
		});
	</script>
</dom-module><commit_msg>[fix] check if user is already registered<commit_after><link rel="import" href="../../vendor/polymer/polymer.html">
<link rel="import" href="../../vendor/paper-button/paper-button.html">
<link rel="import" href="../../vendor/iron-icon/iron-icon.html">
<link rel="import" href="../../vendor/firebase-element/firebase-auth.html">

<dom-module id="fb-login">
	<template>
		<style>
			/* FIXME : use custom variable to change properties */
			:host {
				display: inline-block;
				@apply(--fb-login-container-theme);
			}

			:host paper-button {
				/*Shadow properties*/
				color: 				var(--fb-login-color, #FFFFFF);
				background-color: 	var(--fb-login-bg-color, #3B579D);
				font-weight:		var(--fb-login-fw, bold);				
			}

			paper-button {
				/*Mixin to define custom theme*/
				@apply(--fb-login-theme);
			}

			.icon {
			    --iron-icon-height: 32px;
			    --iron-icon-width: 32px;
			}
		</style>
		<iron-localstorage id="ls" name="app-storage" value="{{storage}}"
			on-iron-localstorage-load-empty="_initLocalStorage"></iron-localstorage>
		<firebase-auth id="auth"
					   location="[[_location]]"
					   on-location-changed="plop"
					   provider="facebook"
					   user="{{fireUser}}"
					   ref="{{ref}}">
		</firebase-auth>
		<paper-button id="loginButton" raised
					  on-tap="login">
			<iron-icon class="icon" src="../../img/FB-f-Logo__blue_50.png"></iron-icon>
			Login
		</paper-button>
	</template>
	<script>
		Polymer({
			is: 'fb-login',
			properties: {
				// Determine if the login action is automatically call
				// NOTE : If declared the test is true
				autoLogin: {
					type: Boolean,
					value: false,
					reflectToAttribute: true
				},
				apiLoaded: {
					type: Boolean,
					value: false,
					observer: '_apiObserver'
				},
				// Graph API URL to call to get data
				graphUrl: {
					type: String,
					value: ""
				},
				// Scope param of permission to ask for
				scope: {
					type: String,
					value: "public_profile"
				},
				// Graph API Response Object
				response: {
					type: Object,
					notify: true
				},
				fireUser: {
					notify: true,
					observer: '_fireUserchanded'
				},
				ref: {
					notify: true
				},
				// Local storage
				storage: {
					type: Object,
					notify: true
				}
			},
			checkLoginStatus: function () {
				var fbLogin = this;
				FB.getLoginStatus(function(response) {
					// Check login status on load, and if the user is already logged in
					if (response.status == 'connected') {
						console.info('Facebook account connected !');
						fbLogin._customLoginAction('connected', {user: fbLogin.fireUser});
					} else if (fbLogin.autoLogin) {
						// Otherwise, show Login dialog first.
						console.info('Facebook account not connected !');
						console.info('Auto login into Facebook !');
						fbLogin.login();
					} else {
						console.info('Facebook account not connected !');
						// Cleanup localstorage access_token
						if (fbLogin.storage.access_token) {
							fbLogin._setAccessToken("");
						}

						fbLogin.$.auth.addEventListener('login', function (e) {
							console.info('Login success into Firebase');
							fbLogin._customLoginAction('connected', e.detail);
						});

						fbLogin.fire('fb-not-connected');
					}
				});
			},
			login: function () {
				var fbLogin = this;

				// Get the connection with the provided scope
				this.scope = this.scope;
				this.$.auth.login({scope: this.scope});
			},
			_locationChanged: function (location) {
				console.log(location);
			},
			_apiObserver: function  (n, o) {
				var fbLogin = this;
				if (n) {
					console.info('Fb API is ready !');

					fbLogin.$.ls.reload()
					fbLogin._location = fbLogin.storage.firebase;

					console.info('Firebase connection established !');

					// Check if the user is actualy connected
					this.checkLoginStatus();

					// bind event to the error login action
					this.$.auth.addEventListener('error', function (e) {
						console.info('Login error into Facebook');
						fbLogin._customLoginAction('false', e.detail);
					});
				}
			},
			_customLoginAction: function (response, param) {
				param = (typeof param !== 'undefined')? param : {};

				var fbLogin = this;
				if (response == 'connected') {

					var access_token = param.user.facebook.accessToken;

					fbLogin._setAccessToken(access_token);

					FB.api(
						'/' + fbLogin.graphUrl,
						{access_token: access_token},
						function(data) {
							fbLogin.response 	= data;
							fbLogin.style.display = 'none';

							// Get the user picture and update the data object
							FB.api(
								"/me/picture",
								{access_token: access_token},
								function (response) {
									if (response && !response.error) {
										var data = fbLogin.response;
											data['picture'] = response;
										fbLogin.response = {};
										fbLogin.response = data;
										console.info('Login success into Facebook');
										fbLogin.fire('fb-login-success', param);
									}
								}
							);
					});
				} else {
					fbLogin.fire('fb-login-canceled', param);
				}
			},
			_initLocalStorage: function () {
				this.storage = {};
			},
			_fireUserchanded: function (fireUser) {
				if (fireUser) {
					console.info("Firebase access granted !");
				}
			},
			_setAccessToken: function (token) {
				var _at = {'access_token': token};
				var tmp = Object.assign(this.storage, _at);
				this.set('storage', {});
				this.set('storage', tmp);
			}
		});
	</script>
</dom-module>
{'fraction_non_alphanumeric': 0.15100518511780223, 'fraction_numerical': 0.001819339579732557, 'mean_word_length': 2.4206596141879277, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3373935', 'n_tokens_mistral': 4719, 'n_tokens_neox': 3341, 'n_words': 759}