pwa-auth 2.0.7 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +65 -54
- package/demonstration/compiled/pwa-auth.js +880 -0
- package/{website → demonstration}/css/styles.css +4 -2
- package/{demo → demonstration}/index.html +7 -4
- package/package.json +12 -10
- package/pwa-auth.js +4 -3
- package/{website → src}/THIRD_PARTY_LICENSES.txt +56 -56
- package/src/compiled/pwa-auth.js +880 -0
- package/{source → src-typescript}/css/form/label.ts +0 -2
- package/src-typescript/css/toggle.ts +9 -0
- package/src-typescript/development/junk/firebase-object.ts +49 -0
- package/src-typescript/development/junk/notes.md +96 -0
- package/src-typescript/development/junk/phone.ts +146 -0
- package/src-typescript/development/junk/photo.ts +440 -0
- package/src-typescript/development/junk/telephone.ts +282 -0
- package/{source/firebase/firebase-login.ts → src-typescript/development/login.ts} +1 -1
- package/{source/firebase/firebase.ts → src-typescript/development/object.ts} +1 -1
- package/src-typescript/firebase/authentication.ts +11 -0
- package/{source/firebase/start.ts → src-typescript/firebase/interface.ts} +35 -64
- package/{source/custom-elements → src-typescript/webcomponents}/drawer/drawer.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/drawer/input/forgot.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/drawer/input/login.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/drawer/input/sign-up.ts +2 -1
- package/{deploy/custom-elements/icon/css/icon.js → src-typescript/webcomponents/icon/css/icon.ts} +4 -3
- package/{source/custom-elements → src-typescript/webcomponents}/icon/icon.ts +2 -21
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/delete.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/email.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/images.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/name.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/password.ts +1 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/input/uploader.ts +2 -1
- package/{source/custom-elements → src-typescript/webcomponents}/settings/settings.ts +2 -2
- package/demo/css/styles.css +0 -67
- package/deploy/css/default.d.ts +0 -5
- package/deploy/css/default.d.ts.map +0 -1
- package/deploy/css/default.js +0 -99
- package/deploy/css/font.d.ts +0 -2
- package/deploy/css/font.d.ts.map +0 -1
- package/deploy/css/font.js +0 -16
- package/deploy/css/form/button.d.ts +0 -3
- package/deploy/css/form/button.d.ts.map +0 -1
- package/deploy/css/form/button.js +0 -54
- package/deploy/css/form/input.d.ts +0 -3
- package/deploy/css/form/input.d.ts.map +0 -1
- package/deploy/css/form/input.js +0 -24
- package/deploy/css/form/label.d.ts +0 -3
- package/deploy/css/form/label.d.ts.map +0 -1
- package/deploy/css/form/label.js +0 -24
- package/deploy/css/form/list.d.ts +0 -3
- package/deploy/css/form/list.d.ts.map +0 -1
- package/deploy/css/form/list.js +0 -22
- package/deploy/css/svg.d.ts +0 -4
- package/deploy/css/svg.d.ts.map +0 -1
- package/deploy/css/svg.js +0 -4
- package/deploy/css/toggle.d.ts +0 -2
- package/deploy/css/toggle.d.ts.map +0 -1
- package/deploy/css/toggle.js +0 -8
- package/deploy/custom-elements/drawer/css/drawer.d.ts +0 -3
- package/deploy/custom-elements/drawer/css/drawer.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/css/drawer.js +0 -55
- package/deploy/custom-elements/drawer/css/exit.d.ts +0 -3
- package/deploy/custom-elements/drawer/css/exit.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/css/exit.js +0 -48
- package/deploy/custom-elements/drawer/css/link.d.ts +0 -3
- package/deploy/custom-elements/drawer/css/link.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/css/link.js +0 -12
- package/deploy/custom-elements/drawer/css/paragraph.d.ts +0 -3
- package/deploy/custom-elements/drawer/css/paragraph.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/css/paragraph.js +0 -10
- package/deploy/custom-elements/drawer/css/toggle.d.ts +0 -3
- package/deploy/custom-elements/drawer/css/toggle.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/css/toggle.js +0 -18
- package/deploy/custom-elements/drawer/drawer.d.ts +0 -37
- package/deploy/custom-elements/drawer/drawer.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/drawer.js +0 -128
- package/deploy/custom-elements/drawer/input/forgot.d.ts +0 -16
- package/deploy/custom-elements/drawer/input/forgot.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/input/forgot.js +0 -60
- package/deploy/custom-elements/drawer/input/login.d.ts +0 -20
- package/deploy/custom-elements/drawer/input/login.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/input/login.js +0 -128
- package/deploy/custom-elements/drawer/input/sign-up.d.ts +0 -20
- package/deploy/custom-elements/drawer/input/sign-up.d.ts.map +0 -1
- package/deploy/custom-elements/drawer/input/sign-up.js +0 -137
- package/deploy/custom-elements/icon/css/icon.d.ts +0 -2
- package/deploy/custom-elements/icon/css/icon.d.ts.map +0 -1
- package/deploy/custom-elements/icon/icon.d.ts +0 -33
- package/deploy/custom-elements/icon/icon.d.ts.map +0 -1
- package/deploy/custom-elements/icon/icon.js +0 -72
- package/deploy/custom-elements/settings/css/navigation.d.ts +0 -2
- package/deploy/custom-elements/settings/css/navigation.d.ts.map +0 -1
- package/deploy/custom-elements/settings/css/navigation.js +0 -51
- package/deploy/custom-elements/settings/input/delete.d.ts +0 -34
- package/deploy/custom-elements/settings/input/delete.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/delete.js +0 -87
- package/deploy/custom-elements/settings/input/email.d.ts +0 -34
- package/deploy/custom-elements/settings/input/email.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/email.js +0 -98
- package/deploy/custom-elements/settings/input/images.d.ts +0 -2
- package/deploy/custom-elements/settings/input/images.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/images.js +0 -22
- package/deploy/custom-elements/settings/input/name.d.ts +0 -33
- package/deploy/custom-elements/settings/input/name.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/name.js +0 -90
- package/deploy/custom-elements/settings/input/password.d.ts +0 -36
- package/deploy/custom-elements/settings/input/password.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/password.js +0 -145
- package/deploy/custom-elements/settings/input/uploader.d.ts +0 -37
- package/deploy/custom-elements/settings/input/uploader.d.ts.map +0 -1
- package/deploy/custom-elements/settings/input/uploader.js +0 -224
- package/deploy/custom-elements/settings/settings.d.ts +0 -37
- package/deploy/custom-elements/settings/settings.d.ts.map +0 -1
- package/deploy/custom-elements/settings/settings.js +0 -197
- package/deploy/firebase/firebase-login.d.ts +0 -21
- package/deploy/firebase/firebase-login.d.ts.map +0 -1
- package/deploy/firebase/firebase-login.js +0 -85
- package/deploy/firebase/firebase.d.ts +0 -20
- package/deploy/firebase/firebase.d.ts.map +0 -1
- package/deploy/firebase/firebase.js +0 -76
- package/deploy/firebase/start.d.ts +0 -14
- package/deploy/firebase/start.d.ts.map +0 -1
- package/deploy/firebase/start.js +0 -86
- package/deploy/lazy-loader.d.ts +0 -11
- package/deploy/lazy-loader.d.ts.map +0 -1
- package/deploy/lazy-loader.js +0 -20
- package/deploy/redux/backend.d.ts +0 -16
- package/deploy/redux/backend.d.ts.map +0 -1
- package/deploy/redux/backend.js +0 -43
- package/deploy/redux/drawer.d.ts +0 -18
- package/deploy/redux/drawer.d.ts.map +0 -1
- package/deploy/redux/drawer.js +0 -21
- package/deploy/redux/frontend.d.ts +0 -17
- package/deploy/redux/frontend.d.ts.map +0 -1
- package/deploy/redux/frontend.js +0 -67
- package/deploy/redux/object.d.ts +0 -24
- package/deploy/redux/object.d.ts.map +0 -1
- package/deploy/redux/object.js +0 -1
- package/deploy/store.d.ts +0 -19
- package/deploy/store.d.ts.map +0 -1
- package/deploy/store.js +0 -13
- package/npm/THIRD_PARTY_LICENSES.txt +0 -303
- package/npm/pwa-auth.js +0 -306
- package/source/css/toggle.ts +0 -9
- package/source/custom-elements/icon/css/icon.ts +0 -70
- package/website/404.html +0 -33
- package/website/css/pwa-styles.css +0 -36
- package/website/images/empty.jpg +0 -0
- package/website/images/favicon.ico +0 -0
- package/website/images/manifest/logo-144.png +0 -0
- package/website/images/manifest/logo-192.png +0 -0
- package/website/images/manifest/logo-48.png +0 -0
- package/website/images/manifest/logo-512.png +0 -0
- package/website/images/manifest/logo-72.png +0 -0
- package/website/images/manifest/logo-96.png +0 -0
- package/website/images/manifest/maskable_icon_x128.png +0 -0
- package/website/images/manifest/maskable_icon_x192.png +0 -0
- package/website/images/manifest/maskable_icon_x384.png +0 -0
- package/website/images/manifest/maskable_icon_x48.png +0 -0
- package/website/images/manifest/maskable_icon_x512.png +0 -0
- package/website/images/manifest/maskable_icon_x72.png +0 -0
- package/website/images/manifest/maskable_icon_x96.png +0 -0
- package/website/index.html +0 -72
- package/website/js/pwa-auth.js +0 -306
- package/website/sitemap.xml +0 -11
- /package/{demo → demonstration}/css/pwa-styles.css +0 -0
- /package/{demo → demonstration}/images/empty.jpg +0 -0
- /package/{npm/images → src}/empty.jpg +0 -0
- /package/{npm → src}/pwa-styles.css +0 -0
- /package/{source → src-typescript}/css/default.ts +0 -0
- /package/{source → src-typescript}/css/font.ts +0 -0
- /package/{source → src-typescript}/css/form/button.ts +0 -0
- /package/{source → src-typescript}/css/form/input.ts +0 -0
- /package/{source → src-typescript}/css/form/list.ts +0 -0
- /package/{source → src-typescript}/css/svg.ts +0 -0
- /package/{source → src-typescript}/lazy-loader.ts +0 -0
- /package/{source → src-typescript}/redux/backend.ts +0 -0
- /package/{source → src-typescript}/redux/drawer.ts +0 -0
- /package/{source → src-typescript}/redux/frontend.ts +0 -0
- /package/{source → src-typescript}/redux/object.ts +0 -0
- /package/{source → src-typescript}/store.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/drawer/css/drawer.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/drawer/css/exit.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/drawer/css/link.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/drawer/css/paragraph.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/drawer/css/toggle.ts +0 -0
- /package/{source/custom-elements → src-typescript/webcomponents}/settings/css/navigation.ts +0 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
|
|
2
|
+
import { html, css, LitElement, CSSResult, PropertyValueMap } from 'lit';
|
|
3
|
+
import { property, state } from 'lit/decorators.js';
|
|
4
|
+
import { store, AppState } from '../../store';
|
|
5
|
+
import { connect } from 'pwa-helpers';
|
|
6
|
+
import { application, auth, db, storage } from '../../firebase/authentication';
|
|
7
|
+
import { iconAuth } from '../../redux/frontend';
|
|
8
|
+
import { updateProfile } from 'firebase/auth';
|
|
9
|
+
import { doc, updateDoc } from 'firebase/firestore';
|
|
10
|
+
import { getStorage, ref, uploadBytes, updateMetadata, getDownloadURL, StorageReference } from "@firebase/storage";
|
|
11
|
+
import { accImage } from '../../redux/backend';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
// Local Development Server
|
|
18
|
+
if ( location.hostname === 'localhost') {
|
|
19
|
+
console.log("localhost detected!");
|
|
20
|
+
connect = {
|
|
21
|
+
apiKey: "AIzaSyAJfm5MahdHr4HzwRLWN7IBhVYXMjP65lQ",
|
|
22
|
+
authDomain: "inmostfire.firebaseapp.com",
|
|
23
|
+
databaseURL: "http://localhost:9000?ns=emulationui",
|
|
24
|
+
projectId: "inmostfire",
|
|
25
|
+
storageBucket: "inmostfire.firebasestorage.app",
|
|
26
|
+
messagingSenderId: "937289126032",
|
|
27
|
+
appId: "1:937289126032:web:0e7f4b679b0f3da6",
|
|
28
|
+
measurementId: "G-DKMV2HFJGE"
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<!-- Google tag (gtag.js)
|
|
35
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DKMV2HFJGE"></script>
|
|
36
|
+
<script>
|
|
37
|
+
window.dataLayer = window.dataLayer || [];
|
|
38
|
+
function gtag(){dataLayer.push(arguments);}
|
|
39
|
+
gtag('set', {'cookie_flags': 'SameSite=None;Secure'});
|
|
40
|
+
gtag('js', new Date());
|
|
41
|
+
gtag('config', 'G-DKMV2HFJGE');
|
|
42
|
+
</script>
|
|
43
|
+
<!--
|
|
44
|
+
<script src="https://www.google.com/recaptcha/enterprise.js?render=6Ld8R6orAAAAAIrAQBX7E_p-rPL7F290cMXaKiFS"></script>
|
|
45
|
+
-->
|
|
46
|
+
|
|
47
|
+
<!-- Cross-Origin Resource Sharing (CORS)
|
|
48
|
+
<meta
|
|
49
|
+
http-equiv="Content-Security-Policy"
|
|
50
|
+
content="
|
|
51
|
+
default-src 'self';
|
|
52
|
+
img-src 'self' https://firebasestorage.googleapis.com https://storage.googleapis.com;
|
|
53
|
+
media-src 'self' https://firebasestorage.googleapis.com;
|
|
54
|
+
connect-src 'self' https://firebasestorage.googleapis.com https://www.google-analytics.com https://firebase.googleapis.com https://identitytoolkit.googleapis.com;
|
|
55
|
+
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com https://www.google-analytics.com https://identitytoolkit.googleapis.com;
|
|
56
|
+
style-src 'self' 'unsafe-inline' ;
|
|
57
|
+
upgrade-insecure-requests;
|
|
58
|
+
base-uri 'self';
|
|
59
|
+
">-->
|
|
60
|
+
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
// UploadPhoto is a LitElement that only renders its content, if it is actually visible.
|
|
64
|
+
// It is a custom element that allows the user to upload a photo to their profile.
|
|
65
|
+
|
|
66
|
+
export class ProtoPhoto extends connect(store)(LitElement) {
|
|
67
|
+
|
|
68
|
+
/** @attr photo */
|
|
69
|
+
@property() public photo : string | void | any = '';
|
|
70
|
+
|
|
71
|
+
@state() private user : string | void = '';
|
|
72
|
+
// @state() private uploadProgress = 0;
|
|
73
|
+
// private uploadComplete = false;
|
|
74
|
+
|
|
75
|
+
constructor() {
|
|
76
|
+
super();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
stateChanged(state: AppState) {
|
|
80
|
+
this.user = state.backend!.userId;
|
|
81
|
+
this.photo = state.backend!.photoURL;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
85
|
+
console.log("contractor photo: ", this.photo);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static get styles():CSSResult {
|
|
89
|
+
return css`
|
|
90
|
+
|
|
91
|
+
:host {
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
-webkit-box-sizing: border-box;
|
|
94
|
+
display: grid;
|
|
95
|
+
grid-template-columns: 1fr;
|
|
96
|
+
grid-gap: 4px;
|
|
97
|
+
width: 100%;
|
|
98
|
+
border-top: 2px solid var(--pwa_divider);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.contractorPhoto {
|
|
102
|
+
border-radius: 50%;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
margin: auto;
|
|
105
|
+
border: 2px solid #303030;
|
|
106
|
+
box-shadow: 1px 1px 2px black, 0 0 25px grey, 0 0 5px #fff;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
label {
|
|
110
|
+
color: var(--pwa_label_text_color);
|
|
111
|
+
box-sizing: border-box;
|
|
112
|
+
width: 100%;
|
|
113
|
+
font-size: smaller;
|
|
114
|
+
margin: auto;
|
|
115
|
+
margin-bottom: 0;
|
|
116
|
+
font-weight: bold;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
`
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
protected render() {
|
|
123
|
+
return html`
|
|
124
|
+
|
|
125
|
+
<!-- Input - Upload Image -->
|
|
126
|
+
<input
|
|
127
|
+
id ="photoURL"
|
|
128
|
+
type ="file"
|
|
129
|
+
name ="photoURL"
|
|
130
|
+
class ="contractorPhoto"
|
|
131
|
+
accept ="image/*"
|
|
132
|
+
@change ="${this.saveImage}"
|
|
133
|
+
style ="
|
|
134
|
+
display: none;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
position: absolute;
|
|
137
|
+
z-index: -1;
|
|
138
|
+
"/>
|
|
139
|
+
|
|
140
|
+
<label
|
|
141
|
+
style="font-size: smaller; font-weight: bold; line-height: 36px;"
|
|
142
|
+
for ="photoURL">Photo:
|
|
143
|
+
|
|
144
|
+
<!-- Output - Retrieved Image -->
|
|
145
|
+
<canvas
|
|
146
|
+
style="
|
|
147
|
+
margin: auto;
|
|
148
|
+
height: 200px;
|
|
149
|
+
width: 100%;
|
|
150
|
+
background-image: url(${this.photo});
|
|
151
|
+
background-size: contain;
|
|
152
|
+
background-repeat: no-repeat;
|
|
153
|
+
background-position: center;
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
box-sizing: border-box;
|
|
157
|
+
">
|
|
158
|
+
</canvas>
|
|
159
|
+
|
|
160
|
+
</label>
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
private appendToFileLocation(filePath: string, appendString: string): string {
|
|
196
|
+
|
|
197
|
+
const lastDotIndex = filePath.lastIndexOf('.'); // Find the last dot to get the file extension
|
|
198
|
+
|
|
199
|
+
if (lastDotIndex <= 0) return filePath; // If there's no dot or it's at the beginning, don't alter the filePath
|
|
200
|
+
|
|
201
|
+
const basePath = filePath.substring(0, lastDotIndex); // Slice the filePath into the base path and extension
|
|
202
|
+
const extension = filePath.substring(lastDotIndex); // Includes the dot
|
|
203
|
+
|
|
204
|
+
console.log('path: ', basePath, appendString, extension);
|
|
205
|
+
|
|
206
|
+
return `${basePath}${appendString}${extension}`; // Append the string and add the extension back
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
private uploadImage = async (file:any) => {
|
|
219
|
+
console.log('upload image');
|
|
220
|
+
try {
|
|
221
|
+
const storage = getStorage(application);
|
|
222
|
+
const storageRef: StorageReference = ref(storage, 'images/' + file.name); // Path where the image will be stored in Firebase Storage
|
|
223
|
+
|
|
224
|
+
// Update metadata properties
|
|
225
|
+
// updateMetadata(location, newMetadata)
|
|
226
|
+
|
|
227
|
+
// Upload the file
|
|
228
|
+
const snapshot = await uploadBytes(storageRef, file);
|
|
229
|
+
|
|
230
|
+
// Get the download URL
|
|
231
|
+
const downloadURL = await getDownloadURL(snapshot.ref);
|
|
232
|
+
console.log('File available at', downloadURL);
|
|
233
|
+
|
|
234
|
+
return downloadURL; // This is the URL you can use to access the image
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.error('Error uploading the file', error);
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
// Save Image to Storage and Database - Update Profile Photo URL in Database and State
|
|
258
|
+
private async saveImage() {
|
|
259
|
+
|
|
260
|
+
// Test: Entry
|
|
261
|
+
console.log('Entry: save image');
|
|
262
|
+
|
|
263
|
+
// let uploader : any = this.shadowRoot!.querySelector('.uploader'); // Select Progress Bar
|
|
264
|
+
const file : any = this.shadowRoot!.querySelector('#photoURL');
|
|
265
|
+
|
|
266
|
+
// Test: File
|
|
267
|
+
console.log('file: ', file);
|
|
268
|
+
|
|
269
|
+
if (!file) {
|
|
270
|
+
console.error('No file selected');
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// const storages = getStorage(application);
|
|
275
|
+
// Test Storage Reference location.fullPath location.name location.bucket
|
|
276
|
+
const location = ref(storage,
|
|
277
|
+
"/" +
|
|
278
|
+
"pwa-auth" +
|
|
279
|
+
"/" +
|
|
280
|
+
this.user +
|
|
281
|
+
"/" +
|
|
282
|
+
file.files[0].name );
|
|
283
|
+
|
|
284
|
+
console.log('location: ', location);
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
/** @type {any} */
|
|
288
|
+
// Create metadata from file information
|
|
289
|
+
const newMetadata = {
|
|
290
|
+
cacheControl: 'public,max-age=300',
|
|
291
|
+
contentType: file.files[0].type // 'image/jpeg'
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
console.log('metadata: ', newMetadata);
|
|
295
|
+
|
|
296
|
+
// Update metadata properties
|
|
297
|
+
updateMetadata(location, newMetadata)
|
|
298
|
+
.then((metadata:any) => { console.log("metadata: ", metadata); }).catch((error:any) => { console.log("error: ", error); });
|
|
299
|
+
|
|
300
|
+
// Upload - Blob or File API
|
|
301
|
+
// const blob = await
|
|
302
|
+
uploadBytes (location, file.files[0], newMetadata).then((snapshot:any) => {
|
|
303
|
+
console.log('uploading: ', snapshot);
|
|
304
|
+
// Get URL
|
|
305
|
+
getDownloadURL(snapshot.ref)
|
|
306
|
+
.then( (url:any) => {
|
|
307
|
+
|
|
308
|
+
const modifiedFilePath = this.appendToFileLocation(url, '_400x400');
|
|
309
|
+
console.log('modifiedFilePath', modifiedFilePath);
|
|
310
|
+
|
|
311
|
+
console.log('url', url);
|
|
312
|
+
// Save URL
|
|
313
|
+
this.personalPhoto(url);
|
|
314
|
+
// let canvas = "https://storage.googleapis.com/v0/b/contractors-centre.appspot.com/o/images/photo.jpg";
|
|
315
|
+
|
|
316
|
+
}).then(
|
|
317
|
+
// let canvas = "https://storage.googleapis.com/{bucket}/{path}";
|
|
318
|
+
).catch( () => {} );
|
|
319
|
+
|
|
320
|
+
}).catch( () => {} );
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
// UPDATE - PROFILE + Firestore Database + STATE - SAVE FILE LOCATION
|
|
351
|
+
private personalPhoto = async (url:string) => {
|
|
352
|
+
|
|
353
|
+
console.log('database save image');
|
|
354
|
+
|
|
355
|
+
if ( auth.currentUser ) {
|
|
356
|
+
console.log("Entry to save database");
|
|
357
|
+
|
|
358
|
+
// Memory allocation for Firestore Database
|
|
359
|
+
// let personal = doc(db, "users", auth.currentUser.uid);
|
|
360
|
+
// let publish = doc(db, "contractors", auth.currentUser.uid);
|
|
361
|
+
|
|
362
|
+
// Update Profile Photo URL in Database - Firestore
|
|
363
|
+
await updateProfile( auth.currentUser, { photoURL: url }).catch((error:Error) => { console.log(error); });
|
|
364
|
+
// await updateDoc( personal, { "contractorPhoto": url } );
|
|
365
|
+
// await updateDoc( publish, { "contractorPhoto": url } );
|
|
366
|
+
console.log("Dispatch Photo");
|
|
367
|
+
// Update Profile Photo URL in State - Redux
|
|
368
|
+
store.dispatch( accImage(url) );
|
|
369
|
+
// store.dispatch( iconAuth(url) );
|
|
370
|
+
|
|
371
|
+
// store.dispatch( businessPhoto(url) ); // store.profile.photoURL
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
customElements.define('proto-photo', ProtoPhoto);
|
|
419
|
+
|
|
420
|
+
declare global {
|
|
421
|
+
interface HTMLElementTagNameMap {
|
|
422
|
+
'proto-photo': ProtoPhoto;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// const resizedLocation = ref(storage, 'images/article/' + file.name + '_400x400' ); // Path where the image will be stored in Firebase Storage
|
|
427
|
+
|
|
428
|
+
// Reset progress bar
|
|
429
|
+
// const percentage = ( snapshot.bytesTransferred / snapshot.totalBytes ) * 0;
|
|
430
|
+
// uploader.value = percentage;
|
|
431
|
+
// console.log('meta size: ', snapshot.metadata);
|
|
432
|
+
|
|
433
|
+
// show progress bar upload
|
|
434
|
+
// const percentage = ( snapshot.bytesTransferred / snapshot.totalBytes ) * 100;
|
|
435
|
+
// uploader.value = percentage;
|
|
436
|
+
|
|
437
|
+
// .then(() => {
|
|
438
|
+
// store.dispatch( businessPhoto(url) ); // Redux Profile Update
|
|
439
|
+
// store.dispatch( individual_Photo(url) );
|
|
440
|
+
// }).catch((error:any) => { console.log(error); });
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
import { CSSResultArray, LitElement, css, html } from "lit";
|
|
4
|
+
import { property, state } from "lit/decorators.js";
|
|
5
|
+
// import { inputStyles, actionButton } from "./css/styles";
|
|
6
|
+
import { auth } from "../../firebase/authentication";
|
|
7
|
+
import { PhoneAuthProvider, updatePhoneNumber } from "firebase/auth";
|
|
8
|
+
import store, { AppState } from "../../store";
|
|
9
|
+
import { accPhone } from "../../redux/backend";
|
|
10
|
+
import { connect } from "pwa-helpers";
|
|
11
|
+
|
|
12
|
+
export class InputTelephone extends connect(store)(LitElement) {
|
|
13
|
+
|
|
14
|
+
/** @attr telephone *
|
|
15
|
+
@property({ type: String, reflect: true}) telephone = '';
|
|
16
|
+
|
|
17
|
+
// Formatted
|
|
18
|
+
@state() private value: string = '';
|
|
19
|
+
|
|
20
|
+
// Unformatted
|
|
21
|
+
@state() private number: number = 0;
|
|
22
|
+
|
|
23
|
+
constructor() { super(); }
|
|
24
|
+
|
|
25
|
+
stateChanged(state: AppState) {
|
|
26
|
+
this.telephone = state.backend!.phone;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
super.connectedCallback();
|
|
31
|
+
this.addFormResetListener();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static get styles(): CSSResultArray { return [ /*inputStyles, actionButton,*
|
|
35
|
+
css`
|
|
36
|
+
|
|
37
|
+
:host, form { display: grid; }
|
|
38
|
+
|
|
39
|
+
`
|
|
40
|
+
]; }
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
return html`
|
|
44
|
+
|
|
45
|
+
<form
|
|
46
|
+
@submit="${this.default}">
|
|
47
|
+
|
|
48
|
+
<label
|
|
49
|
+
for="pwa-telephone">Telephone:</label>
|
|
50
|
+
|
|
51
|
+
<input
|
|
52
|
+
id="pwa-telephone"
|
|
53
|
+
name="telephone" v
|
|
54
|
+
type="text"
|
|
55
|
+
@input="${this.onInput}"
|
|
56
|
+
@change="${this.handleTelephone}"
|
|
57
|
+
@keydown="${this.onKeyDown}"
|
|
58
|
+
placeholder="${this.formatPhoneNumber(this.telephone) || '(XXX) XXX-XXXX'}"
|
|
59
|
+
inputmode="numeric"
|
|
60
|
+
pattern="[0-9]*"
|
|
61
|
+
data-label="Phone Number"
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<button
|
|
65
|
+
class="action-button"
|
|
66
|
+
@click="${this.saveTelephone}">Update
|
|
67
|
+
</button>
|
|
68
|
+
|
|
69
|
+
</form>
|
|
70
|
+
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
private onKeyDown(event: KeyboardEvent) {
|
|
78
|
+
|
|
79
|
+
// Allow backspace, delete, tab, escape, enter, and arrow keys
|
|
80
|
+
const allowedKeys = ['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'];
|
|
81
|
+
|
|
82
|
+
if (allowedKeys.includes(event.key) || (event.key >= '0' && event.key <= '9') || (event.key >= 'Numpad0' && event.key <= 'Numpad9')) {
|
|
83
|
+
// Allow normal operation
|
|
84
|
+
} else {
|
|
85
|
+
// Prevent the default action (e.g., character input)
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private onInput(event: Event) {
|
|
92
|
+
|
|
93
|
+
const inputElement = event.target as HTMLInputElement;
|
|
94
|
+
const unformattedValue = this.unformatPhoneNumber(inputElement.value);
|
|
95
|
+
|
|
96
|
+
// Check the length of the unformatted phone number
|
|
97
|
+
if (unformattedValue.length <= 10) {
|
|
98
|
+
this.value = unformattedValue;
|
|
99
|
+
} else {
|
|
100
|
+
// If the length exceeds 10, reset the input value to the previously stored value
|
|
101
|
+
inputElement.value = this.formatPhoneNumber(this.value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private formatPhoneNumber(phoneNumber: string): string {
|
|
106
|
+
const cleaned = ('' + phoneNumber).replace(/\D/g, '');
|
|
107
|
+
let formatted = '';
|
|
108
|
+
|
|
109
|
+
if (cleaned.length > 0) {
|
|
110
|
+
formatted = `(${cleaned.slice(0, 3)}`;
|
|
111
|
+
}
|
|
112
|
+
if (cleaned.length >= 3) {
|
|
113
|
+
formatted += `) ${cleaned.slice(3, 6)}`;
|
|
114
|
+
}
|
|
115
|
+
if (cleaned.length > 6) {
|
|
116
|
+
formatted += `-${cleaned.slice(6, 10)}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return formatted;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private unformatPhoneNumber(formattedPhoneNumber: string): string {
|
|
123
|
+
return formattedPhoneNumber.replace(/\D/g, '');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private addFormResetListener() {
|
|
127
|
+
const form = this.closest('form');
|
|
128
|
+
if (form) {
|
|
129
|
+
form.addEventListener('reset', () => this.resetInput());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private resetInput() {
|
|
134
|
+
this.value = '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
/* Form Default *
|
|
147
|
+
private default = (e:Event) => {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
}
|
|
150
|
+
/*
|
|
151
|
+
// Handle input changes to keep the password property in sync
|
|
152
|
+
private handleTelephone(event: Event) {
|
|
153
|
+
const input = event.target as HTMLInputElement;
|
|
154
|
+
this.number = input.value; // Update the property with the input value
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Save Email
|
|
158
|
+
private saveTelephone = async () => {
|
|
159
|
+
|
|
160
|
+
if ( auth.currentUser ) {
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// Step 1: Verify the new phone number
|
|
166
|
+
PhoneAuthProvider.credentialWithPhoneNumbers("+1234567890")
|
|
167
|
+
.then((verificationId) => {
|
|
168
|
+
// Prompt user to enter the SMS code
|
|
169
|
+
const smsCode = "123456"; // User enters this
|
|
170
|
+
const credential = PhoneAuthProvider.credential(verificationId, smsCode);
|
|
171
|
+
|
|
172
|
+
// Step 2: Update the user's phone number
|
|
173
|
+
updatePhoneNumber(auth.currentUser, credential)
|
|
174
|
+
.then(() => {
|
|
175
|
+
console.log("Phone number updated successfully!");
|
|
176
|
+
})
|
|
177
|
+
.catch((error) => {
|
|
178
|
+
console.error("Error updating phone number:", error);
|
|
179
|
+
});
|
|
180
|
+
})
|
|
181
|
+
.catch((error) => {
|
|
182
|
+
console.error("Error verifying phone number:", error);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// Change Email Firebase Function
|
|
191
|
+
await updatePhoneNumber(
|
|
192
|
+
// auth.PhoneAuthProvider.credential(verificationId, verificationCode).catch((error:Error) => { console.log(error); });
|
|
193
|
+
auth.currentUser, this.number ).catch((error:Error) => { console.log(error); });
|
|
194
|
+
|
|
195
|
+
// Dispatch Custom Event
|
|
196
|
+
store.dispatch(accPhone(this.number));
|
|
197
|
+
|
|
198
|
+
alert('Telephone Updated: ' + this.number);
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
customElements.define('input-telephone', InputTelephone);
|
|
207
|
+
|
|
208
|
+
declare global {
|
|
209
|
+
interface HTMLElementTagNameMap {
|
|
210
|
+
'input-telephone': InputTelephone;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
// this.emailVerification();
|
|
218
|
+
// let document :any = doc( db, 'users', auth.currentUser.uid );
|
|
219
|
+
// .then(() => updateDoc( document, { "contractorEmail":contactMail.email } ).catch(e=>console.log(e)) )
|
|
220
|
+
// store.dispatch( businessEmail(contactMail.email) ); // Redux Account Update
|
|
221
|
+
// console.log('good');
|
|
222
|
+
/*
|
|
223
|
+
// Email Verification
|
|
224
|
+
private emailVerification() {
|
|
225
|
+
|
|
226
|
+
// const auth : any = getAuth();
|
|
227
|
+
console.log( 'auth.currentUser: ', auth.currentUser);
|
|
228
|
+
|
|
229
|
+
// Todo: Find Soruce of Dependency
|
|
230
|
+
sendEmailVerification(auth.currentUser)
|
|
231
|
+
.then(() => { console.log('success')
|
|
232
|
+
// Email verification sent!
|
|
233
|
+
}).catch( e => console.log(e) );
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
/*
|
|
240
|
+
// Module Declaration Exact NameSpace Reference - Asynchronous Firebase Function
|
|
241
|
+
export const google_SignIn = async () => {
|
|
242
|
+
|
|
243
|
+
const provider:any = new GoogleAuthProvider();
|
|
244
|
+
provider.addScope('profile');
|
|
245
|
+
provider.addScope('email');
|
|
246
|
+
|
|
247
|
+
signInWithRedirect(auth, provider);
|
|
248
|
+
|
|
249
|
+
const credential = GoogleAuthProvider.credential(
|
|
250
|
+
googleUser.getAuthResponse().id_token
|
|
251
|
+
);
|
|
252
|
+
const result = await signInWithCredential(auth, credential);
|
|
253
|
+
|
|
254
|
+
getRedirectResult(auth)
|
|
255
|
+
.then( (result: any) => {
|
|
256
|
+
if (result.credential) { /*Access Token to access Google API
|
|
257
|
+
const token = result.credential.accessToken; console.log("Google Token", token); }
|
|
258
|
+
// The signed-in user info.
|
|
259
|
+
// const firebaseUser = result.firebaseUser;
|
|
260
|
+
}).catch( (error:any) => { console.log('Sign in error: ', error); } );
|
|
261
|
+
|
|
262
|
+
// GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
|
|
263
|
+
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/*
|
|
270
|
+
// Module Declaration Exact NameSpace Reference - Asynchronous Firebase Function
|
|
271
|
+
export const anon_SignIn = async () => {
|
|
272
|
+
|
|
273
|
+
signInAnonymously(auth)
|
|
274
|
+
.then(() => { })
|
|
275
|
+
.catch((error) => {
|
|
276
|
+
const errorCode = error.code;
|
|
277
|
+
const errorMessage = error.message;
|
|
278
|
+
console.log(errorCode, errorMessage);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
*/
|