Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Telegram Auth #325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/CampusClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export const config = {
appId: '1214335051921931',
redirectUrl: `${ApplicationConfiguration.ApiEndpoint}account/oauth/login/fb`,
},
telegram: {
botName: 'kpi_ua_bot',
},
appDomains: [
'kpi.ua',
'campus.kpi.ua',
Expand Down Expand Up @@ -124,27 +121,7 @@ export const authByKpiId = async (phone, secret) => {
return await getCurrentUser();
};

/**
* Authorize in Campus API with Telegram
* @param telegramResponse
* @returns {Promise<*>}
*/
export const authViaTelegram = async (telegramResponse) => {
const response = await callApi(
'Account/oauth/login/telegram',
'POST',
telegramResponse,
);

if (response.status < 200 || response.status >= 300) {
return null;
}

const credentials = await response.json();
await storeCredentials(credentials.sessionId, credentials.access_token);

return await getCurrentUser(true);
};

/**
* Logout from system
Expand Down
18 changes: 0 additions & 18 deletions src/components/AuthContainerDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState } from 'react';
import AuthForm from './AuthForm';
import * as campus from '../CampusClient';
import { useHistory } from 'react-router-dom';
import TelegramLoginWidget from './TelegramLoginWidget';

const AuthContainerDefault = () => {
const [authFail, setAuthFail] = useState(false);
Expand All @@ -20,17 +19,6 @@ const AuthContainerDefault = () => {
}
};

const handleTelegramResponse = async (telegramResponse) => {
const user = await campus.authViaTelegram(telegramResponse);

setAuthFail(!user);

if (!!user) {
history.push(`/home`);
window.location.reload();
}
};

const dismissInvalid = () => setAuthFail(false);

return (
Expand Down Expand Up @@ -60,12 +48,6 @@ const AuthContainerDefault = () => {
{/* </a>*/}
{/*</div>*/}

<div className="form-group">
<TelegramLoginWidget
callbackOnAuth={handleTelegramResponse}
botName={campus.config.telegram.botName}
/>
</div>
</AuthForm>
);
};
Expand Down
31 changes: 1 addition & 30 deletions src/components/SettingsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import * as campus from '../CampusClient';
import { Link, Redirect } from 'react-router-dom';
import ProgressBar from './ProgressBar';
import UserProfileImage from './UserProfileImage';
import TelegramLoginWidget from './TelegramLoginWidget';

class SettingsEditor extends React.Component {
state = {
user: {
tgAuthLinked: '',
},
user: { },
selectedFile: null,
email: '',
currentPassword: '',
Expand Down Expand Up @@ -149,20 +146,7 @@ class SettingsEditor extends React.Component {
handleSelectedFile = async (event) =>
this.setState({ selectedFile: event.target.files[0] });

handleTelegramResponse = async (telegramResponse) => {
const user = await campus.authViaTelegram(telegramResponse);

await this.setState({ authFail: !user });

if (!!user) {
this.props.history.push(`/settings-editor`);
this.setState({ user });

alert('Ви пiдключили авторизацiю через Telegram.');

this.setState({redirect: '/settings'});
}
};

render() {

Expand Down Expand Up @@ -277,19 +261,6 @@ class SettingsEditor extends React.Component {
/>
<br />
<br />
<h4>Telegram (beta)</h4>
<TelegramLoginWidget
callbackOnAuth={this.handleTelegramResponse}
botName={campus.config.telegram.botName}
/>
Cтатус:{' '}
<b>
{!!this.state.user.tgAuthLinked
? `пiдключено`
: `не пiдключено`}
</b>
<br />
<br />
</div>
</div>

Expand Down
48 changes: 0 additions & 48 deletions src/components/TelegramLoginWidget.js

This file was deleted.