Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
derevnjuk committed Jan 27, 2022
2 parents 4e3288e + 0424660 commit bbb9541
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 44 deletions.
24 changes: 15 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions public/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions public/src/api/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function getProducts(): Promise<Product[]> {
return makeApiRequest({
url: ApiUrl.Products,
method: 'get',
headers: { authorization: sessionStorage.getItem('token') }
headers: {
authorization:
sessionStorage.getItem('token') || localStorage.getItem('token')
}
});
}

Expand All @@ -42,7 +45,10 @@ export function postTestimonials(data: Testimonial): Promise<any> {
return makeApiRequest({
url: ApiUrl.Testimonials,
method: 'post',
headers: { authorization: sessionStorage.getItem('token') },
headers: {
authorization:
sessionStorage.getItem('token') || localStorage.getItem('token')
},
data
});
}
Expand Down Expand Up @@ -132,7 +138,10 @@ export function getUserPhoto(email: string): Promise<any> {
return makeApiRequest({
url: `${ApiUrl.Users}/one/${email}/photo`,
method: 'get',
headers: { authorization: sessionStorage.getItem('token') },
headers: {
authorization:
sessionStorage.getItem('token') || localStorage.getItem('token')
},
responseType: 'arraybuffer'
});
}
Expand All @@ -141,7 +150,10 @@ export function getAdminStatus(email: string): Promise<any> {
return makeApiRequest({
url: `${ApiUrl.Users}/one/${email}/adminpermission`,
method: 'get',
headers: { authorization: sessionStorage.getItem('token') }
headers: {
authorization:
sessionStorage.getItem('token') || localStorage.getItem('token')
}
});
}

Expand All @@ -151,7 +163,8 @@ export function putUserData(user: UserData): Promise<UserData> {
method: 'put',
headers: {
'content-type': 'application/json',
'authorization': sessionStorage.getItem('token')
'authorization':
sessionStorage.getItem('token') || localStorage.getItem('token')
},
data: user
});
Expand All @@ -166,7 +179,8 @@ export function putPhoto(photo: File, email: string): Promise<any> {
method: 'put',
headers: {
'content-type': 'image/png',
'authorization': sessionStorage.getItem('token')
'authorization':
sessionStorage.getItem('token') || localStorage.getItem('token')
},
data
});
Expand Down
6 changes: 3 additions & 3 deletions public/src/api/makeApiRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export function makeApiRequest<T>(
.then((response) => {
const token = response.headers.authorization;
token && sessionStorage.setItem('token', token);

return response.data;
})
.catch((error) => {
switch (error.response.status) {
case 401:
sessionStorage.removeItem('email');
sessionStorage.removeItem('token');
sessionStorage.removeItem('userName');
sessionStorage.clear();
localStorage.clear();
return {
...error,
errorText:
Expand Down
1 change: 1 addition & 0 deletions public/src/interfaces/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface LoginUser {
csrf?: string;
op?: LoginFormMode;
fingerprint?: string;
rememberuser?: string;
}

export enum LoginFormMode {
Expand Down
2 changes: 1 addition & 1 deletion public/src/pages/auth/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAdminStatus } from '../../api/httpClient';
import AuthLayout from './AuthLayout';

export const AdminPage: FC = () => {
const user = sessionStorage.getItem('email');
const user = sessionStorage.getItem('email') || localStorage.getItem('email');
const [isAdmin, setIsAdmin] = useState<boolean>(false);

useEffect(() => {
Expand Down
37 changes: 32 additions & 5 deletions public/src/pages/auth/LoginNew/PasswordCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,32 @@ export const PasswordCheck: FC = () => {
if (errorText) {
setErrorText(errorText);
} else {
sessionStorage.setItem('email', email);
if (form.rememberuser) {
localStorage.setItem(
'email',
sessionStorage.getItem('email') || ''
);
localStorage.setItem(
'token',
sessionStorage.getItem('token') || ''
);
sessionStorage.clear();
}
}
return getUserData(email);
})
.then((userData: UserData) => {
sessionStorage.setItem(
'userName',
`${userData.firstName} ${userData.lastName}`
);
if (form.rememberuser) {
localStorage.setItem(
'userName',
`${userData.firstName} ${userData.lastName}`
);
} else {
sessionStorage.setItem(
'userName',
`${userData.firstName} ${userData.lastName}`
);
}
window.location.href = RoutePath.Home;
});
};
Expand All @@ -79,6 +96,16 @@ export const PasswordCheck: FC = () => {
value={password}
onInput={onInput}
/>
<label htmlFor="rememberuser">
<input
type="checkbox"
id="rememberuser"
name="rememberuser"
value="true"
onChange={onInput}
/>
&nbsp;Remember me
</label>
</div>
<button
className="au-btn au-btn--block au-btn--green m-b-20"
Expand Down
10 changes: 5 additions & 5 deletions public/src/pages/main/Header/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
import { RoutePath } from '../../../router/RoutePath';

export const Sign: FC = () => {
const user = sessionStorage.getItem('email');
const userName = sessionStorage.getItem('userName');
const user = sessionStorage.getItem('email') || localStorage.getItem('email');
const userName =
sessionStorage.getItem('userName') || localStorage.getItem('userName');
const [isAdminUser, setIsAdminUser] = useState<boolean>(false);
const [userImage, setUserImage] = useState<string | null>();

Expand Down Expand Up @@ -43,9 +44,8 @@ export const Sign: FC = () => {
};

const logout = () => {
sessionStorage.removeItem('email');
sessionStorage.removeItem('token');
sessionStorage.removeItem('userName');
sessionStorage.clear();
localStorage.clear();
window.location.reload();
};

Expand Down
12 changes: 10 additions & 2 deletions public/src/pages/main/Userprofile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const defaultUserData: UserData = {
};

export const Userprofile = () => {
const email: string | null = sessionStorage.getItem('email');
const email: string | null =
sessionStorage.getItem('email') || localStorage.getItem('email');
const [user, setUser] = useState<UserData>(defaultUserData);

const onInput = ({ target }: { target: EventTarget | null }) => {
Expand All @@ -30,7 +31,14 @@ export const Userprofile = () => {
const sendUserData = (e: FormEvent) => {
e.preventDefault();
putUserData(user).then(() => {
sessionStorage.setItem('userName', `${user.firstName} ${user.lastName}`);
if (localStorage.getItem('email')) {
localStorage.setItem('userName', `${user.firstName} ${user.lastName}`);
} else {
sessionStorage.setItem(
'userName',
`${user.firstName} ${user.lastName}`
);
}
window.location.href = RoutePath.Home;
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Props {
}

export const TestimonialsForm: FC<Props> = (props: Props) => {
const user = sessionStorage.getItem('email');
const user = sessionStorage.getItem('email') || localStorage.getItem('email');

const [form, setForm] = useState<Testimonial>(defaultTestimonial);
const { name, title, message } = form;
Expand Down
2 changes: 1 addition & 1 deletion public/src/router/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AdminPage from '../pages/auth/AdminPage';
import PasswordCheck from '../pages/auth/LoginNew/PasswordCheck';

export const Routes: FC = () => {
const user = sessionStorage.getItem('email');
const user = sessionStorage.getItem('email') || localStorage.getItem('email');

return (
<Switch>
Expand Down
13 changes: 9 additions & 4 deletions src/file/cloud.providers.metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';

@Injectable()
export class CloudProvidersMetaData {
Expand Down Expand Up @@ -29,7 +30,7 @@ export class CloudProvidersMetaData {
tags
guest-attributes
maintenance-event
network-interfaces/
network-interfaces/
`.trim(),
);
this.providers.set(
Expand Down Expand Up @@ -207,7 +208,7 @@ export class CloudProvidersMetaData {
"macAddress": "0011AAFFBB22"
}]
}
}
}
`.trim(),
);
this.providers.set(
Expand Down Expand Up @@ -257,7 +258,7 @@ export class CloudProvidersMetaData {
);
}

get(providerUrl: string): string {
async get(providerUrl: string): Promise<string> {
if (providerUrl.startsWith(CloudProvidersMetaData.GOOGLE)) {
return this.providers.get(CloudProvidersMetaData.GOOGLE);
} else if (providerUrl.startsWith(CloudProvidersMetaData.DIGITAL_OCEAN)) {
Expand All @@ -267,7 +268,11 @@ export class CloudProvidersMetaData {
} else if (providerUrl.startsWith(CloudProvidersMetaData.AZURE)) {
return this.providers.get(CloudProvidersMetaData.AZURE);
} else {
return null;
const { data } = await axios(providerUrl, {
timeout: 5000,
responseType: 'text',
});
return data;
}
}
}
2 changes: 1 addition & 1 deletion src/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FileService {

return fs.createReadStream(file);
} else if (file.startsWith('http')) {
const content = this.cloudProviders.get(file);
const content = await this.cloudProviders.get(file);

if (content) {
return Readable.from(content);
Expand Down

0 comments on commit bbb9541

Please sign in to comment.