Skip to content

Instantly share code, notes, and snippets.

View azzeddineCH's full-sized avatar
🛠️
shipping

Azzeddine CHENINE azzeddineCH

🛠️
shipping
View GitHub Profile
if (fileName.startsWith('thumb_')) {
console.log("the thumbnail is already created");
return
}
exports.generateProfileThumbnail = functions.storage.object().onChange(event => {
const data = event.data;
const filePath = data.name;
const fileName = filePath.split("/").pop();
const tmpFilePath = "/tmp/" + fileName;
const thumbFilePath = "/users/profileImages/thumb_" + fileName;
const metageneration = data.metageneration;
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"@google-cloud/storage": "^1.2.0",
"child-process-promise": "^2.2.1",
"firebase-admin": "~4.2.1",
"firebase-functions": "^0.5"
},
"private": true
var functions = require('firebase-functions');
const gcs = require('@google-cloud/storage')({
keyFilename: "chatme-30a53-firebase-adminsdk-spbrj-95b05f5e2e-1.json"
});
const spawn = require('child-process-promise').spawn;
var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createUserAccount = functions.auth.user().onCreate(event => {
const email = event.data.email;
const uid = event.data.uid;
const photoURL = event.data.photoURL || "";
var username = event.data.displayName;
/**
* a method to handle the state of the auth widgets, it displays a progress bar while the
* firebase authentication network process
* @param state if true the progress bar will be shown
* @param view holds the auth widget to hide or dispaly
*/
private void showProgress(boolean state,View view){
mProgressBarContainer =view.findViewById(R.id.progress_bar_container);
mEmailPasswordAuthContainer = view.findViewById(R.id.email_password_auth_container);
if(state) {
/**
* a public method to handel the facebook authentication
*
* @param token holds the user Facebook accessToken
*/
public void handleFacebookAccessToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
FirebaseUtils.auth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
/**
* a public method to handel the user sign up event from the auth fragment
*
* @param email a string holds the user email address
* @param password a string holds the user text password
* @param view a view holds the auth widgets to hide
*
*
*/
public void handleSignUp(String email, String password, final View view){
/**
* a public method to handel the user sign in event from the auth fragment
*
* @param email a string holds the user email address
* @param password a string holds the user text password
* @param view a view holds the auth widgets to hide
*/
public void handleSignIn(String email, String password, final View view){
showProgress(true,view);
FirebaseUtils.auth.signInWithEmailAndPassword(email, password).addOnCompleteListener(
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {