Browse Source

calendar v3

filipe
henrydays 3 years ago
parent
commit
116fc1b3a9
  1. 8
      App/app/Router.js
  2. 13
      App/app/screens/Calendar.js
  3. 5
      App/app/screens/Home.js
  4. 60
      App/app/screens/calendarDetail.js
  5. 19
      App/app/screens/choosePath.js
  6. 1
      App/app/store/actions/actionTypes.js
  7. 306
      App/app/store/actions/api.js
  8. 4
      App/app/store/actions/index.js
  9. 65
      App/app/store/reducers/api.js
  10. 41
      api/Controllers/AuthController.cs
  11. 23
      api/Dtos/tokenDto.cs
  12. 18
      api/Dtos/userDetails.cs
  13. 2
      api/Startup.cs
  14. 11
      api/api.csproj
  15. 2
      api/obj/Debug/netcoreapp2.1/project.razor.json

8
App/app/Router.js

@ -104,10 +104,7 @@ const AppStack = createBottomTabNavigator(
},
{
//initialRouteName: 'Home',
initialRouteName: 'Eventos',
//initialRouteName: 'Calendário',
initialRouteName: 'Home',
tabBarOptions: {
showLabel: true, // hide labels
@ -125,7 +122,8 @@ const Stack = createStackNavigator({
screen: AppStack,
navigationOptions: ({navigation}) => {
const index = navigation.state.index;
if (navigation.state.routes[index].routeName == 'Home') {
return {
headerTitle: `${navigation.state.routes[index].routeName}`,

13
App/app/screens/Calendar.js

@ -19,7 +19,7 @@ import * as Progress from "react-native-progress";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import PTRView from 'react-native-pull-to-refresh';
import * as Actions from "../store/actions"; //Import your actionss
const formatObj = obj => {
@ -140,6 +140,10 @@ class Calendar extends React.Component {
constructor() {
super();
}
_refresh=()=>{
this.props.getEvents(this.props.user);
this.props.getSessions(this.props.userDetails.token);
}
render() {
const ThirdRoute = () => (
@ -275,7 +279,9 @@ class Calendar extends React.Component {
);
return (
<View style={{ flex: 1 }}>
<View>
{this.props.careerPath != undefined && (
<Text
@ -292,6 +298,7 @@ class Calendar extends React.Component {
</Text>
)}
</View>
<TabView
navigationState={this.state}
renderScene={SceneMap({
@ -310,7 +317,11 @@ class Calendar extends React.Component {
style={{ backgroundColor: "#F2F2F2" }}
indicatorStyle={{ backgroundColor: "pink" }}
/>
<Button onPress={this._refresh} title="Close" color="#841584"
accessibilityLabel="Learn more about this purple button"/>
</View>
);
}
}

5
App/app/screens/Home.js

@ -155,10 +155,11 @@ _update=()=>{
<View style={styles.userImageContainer}>
<Image style={styles.userImage} source={{uri: 'https://i.imgur.com/XXJ7LxV.jpg'}}/>
</View>
{this.props.user!=undefined &&
<Text style={styles.userText}>{this.props.user.Name}</Text>
}
<Text style={styles.userTextSub}>{this.props.user.Company}</Text>
</View>
</ImageBackground>

60
App/app/screens/calendarDetail.js

@ -50,11 +50,12 @@ const formatObj = (obj) => {
class calendarDetail extends React.Component {
static navigationOptions = ({navigation}) => ({
header: (
<NavAbsolute
navigation={navigation}
title={navigation.state.params.info.name}
// title={navigation.state.params.info.name}
/>
),
});
@ -67,6 +68,11 @@ class calendarDetail extends React.Component {
this.props.getEvents(this.props.user);
console.log('didMount');
console.log(this.props.events);
const {navigation} = this.props;
const info = navigation.getParam('info', 'error');
console.log("putas")
console.log(info)
}
@ -103,29 +109,35 @@ class calendarDetail extends React.Component {
renderDescription = (info) => {
return (
<View>
<View style={styles.cardContainer}>
<View style={styles.header}>
<View style={{flexDirection: "row", alignItems: 'center', alignSelf:'center'}}>
<Text style={styles.ramoText}>Onde está o ramo? xD </Text>
<View style={styles.timeText}>
<Text style={{color: "#CC1A17", fontSize: 15}}>
{info.time === info.timeEnd ? info.time : `${info.time} - ${info.timeEnd}`}
</Text>
</View>
</View>
<View style={styles.details}>
<Text style={styles.nameAttendee}>Attendee Name</Text>
<View><Text style={{margin:10,marginTop:0, fontSize:20, color:'#CC1A17'}}>{info.name}</Text></View>
<View style={{margin:10}}>
<Progress.Bar color={'#000000'} progress={info.Enrolled / info.MaxAttendees} height={10}
unfilledColor={'white'} width={210}/>
<Text style={{alignSelf: "center"}}>{info.Enrolled} / {info.MaxAttendees}</Text>
<Text >{info.Enrolled} / {info.MaxAttendees}</Text>
</View>
<Divider style={{backgroundColor: '#000'}}/>
<View>
<Text style={{fontSize:15, color:'#CC1A17', padding:10}}>Descrição</Text>
<Text style={{paddingLeft:10, paddingRigh:10}}></Text>
</View>
</View>
<View style={styles.cardContainer}>
<View style={styles.block}>
<Text style={{fontSize: 20, color: "#CC1A17"}}>Descrição</Text>
<Divider style={{backgroundColor: '#000'}}/>
<View style={{marginTop: 10}}>
<Text style={{fontSize: 10}}>
<Text>
{info.description}
</Text>
</View>
@ -197,7 +209,7 @@ class calendarDetail extends React.Component {
render() {
const {navigation} = this.props;
const info = navigation.getParam('info', 'error');
console.log(info);
return (
@ -209,15 +221,15 @@ class calendarDetail extends React.Component {
</View>
{this.renderDescription(info)}
</View>
<View style={styles.cardContainer}>
<View style={styles.block}>
<Text style={{fontSize: 20, color: "#CC1A17"}}>Localização</Text>
<Divider style={{backgroundColor: '#000', marginBottom: 10}}/>
</View>
</ScrollView>
<Divider style={{backgroundColor: 'black'}}/>
{this.renderAttendee()}
</View>
)
@ -227,6 +239,12 @@ class calendarDetail extends React.Component {
const styles = StyleSheet.create({
block:{
marginTop:15,
backgroundColor:'white',
padding:20
},
AttendeeContainer: {
flexDirection: 'row',
height: 55,
@ -286,8 +304,8 @@ const styles = StyleSheet.create({
ramoText: {
alignSelf: 'flex-start',
marginBottom: 5,
color: '#000',
fontSize: 20,
color: 'white',
fontSize: 17,
fontWeight: '400',
},
@ -310,10 +328,17 @@ const styles = StyleSheet.create({
//marginBottom: 55,
},
header:{
flex: 1,
padding: 10,
backgroundColor: 'white',
borderRadius: 0,
},
cardContainer: {
flex: 1,
padding: 10,
margin: 20,
// margin: 20,
backgroundColor: 'white',
borderRadius: 5,
},
@ -412,7 +437,8 @@ function mapStateToProps(state, props) {
token: state.apiReducer.token,
user: state.apiReducer.user,
logged: state.apiReducer.logged,
events: state.apiReducer.events
events: state.apiReducer.events,
careerPath: state.apiReducer.careerPath,
}
}

19
App/app/screens/choosePath.js

@ -324,7 +324,14 @@ class choosePath extends React.Component {
<View style={styles.session}>
{this._verifySession(item[index].Id) && (
<TouchableOpacity
onPress={() => {}}
onPress={() => {
this.props.removeSession(
this.props.user,
this.props.userDetails.token,
item[index].Id
);
}}
style={{ flex: 1, alignSelf: "center" }}
>
<View>
@ -339,11 +346,14 @@ class choosePath extends React.Component {
{!this._verifySession(item[index].Id) && (
<TouchableOpacity
onPress={() => {
this.props.waitChangeGuest()
//this.props.waitChangeGuest()
this.props.signSession(
this.props.user,
this.props.userDetails.token,
item[index].Id
);
}}
style={{ flex: 1, alignSelf: "center" }}
>
@ -395,11 +405,12 @@ class choosePath extends React.Component {
</View>
{(this.props.changingGuest || this.props.Blocks == true) && (
<View style={{ flex:1, height:SCREEN_HEIGHT*0.6, alignSelf:'center',}}>
<ActivityIndicator
size="large"
color="red"
style={{ flex: 1, alignContent: "center" }}
/>
style={{ alignContent: "center" , alignSelf:'center', marginTop:SCREEN_HEIGHT*0.2}}
/></View>
)}
</ScrollView>
</View>

1
App/app/store/actions/actionTypes.js

@ -17,6 +17,7 @@ export const CHANGE_GUEST = 'CHANGE_GUEST'
export const GET_SESSIONS= 'GET_SESSIONS'
export const SIGN_SESSION= 'SIGN_SESSION'
export const WAIT_CHANGE='WAIT_CHANGE'
export const REMOVE_SESSION = 'REMOVE_SESSION'
//UI

306
App/app/store/actions/api.js

@ -1,6 +1,6 @@
import { AsyncStorage } from "react-native";
import { NetInfo , Alert} from "react-native";
import { NetInfo, Alert } from "react-native";
var _ = require("lodash");
@ -20,7 +20,8 @@ import {
WAIT_CHANGE,
SIGN_SESSION,
OPEN_MODAL,
LOADINGLOGIN
LOADINGLOGIN,
REMOVE_SESSION
} from "./actionTypes"; //Import the actions types constant we defined in our actions
import moment from "moment";
@ -39,44 +40,37 @@ axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
const map = require("lodash/fp/map").convert({ cap: false });
export function waitLogin(){
return dispatch=>{
export function waitLogin() {
return dispatch => {
dispatch({
type: LOADINGLOGIN,
type: LOADINGLOGIN
});
}
};
}
//faz autenticação com API interna
export function loginInternal(userDetails){
//faz autenticação com API interna
export function loginInternal(userDetails) {
axios.defaults.baseURL = "http://127.0.0.1:5000";
return dispatch => {
axios.post('/api/login',{
"username": "cena",
"password": "password"
}).then(a=>{
console.log("sucesso!")
console.log(a)
}).catch(p=>{
console.log(p)
})
axios
.post("/api/login", {
username: "cena",
password: "password"
})
.then(a => {
console.log("sucesso!");
console.log(a);
})
.catch(p => {
console.log(p);
});
dispatch({
type: OPEN_MODAL,
type: OPEN_MODAL
});
};
}
export function openModal(info, t) {
return dispatch => {
dispatch({
@ -124,27 +118,27 @@ function getCareerPath(sessions) {
for (let key in sessions) {
if (sessions[key].Name == "IA") {
careerPath = "Artificial Inteligence";
careerColor='#CC1A17'
careerColor = "#CC1A17";
}
if (sessions[key].Name == "IOT") {
careerPath = "Internet of Things";
careerColor= "green"
careerColor = "green";
}
if (sessions[key].Name == "WEB") {
careerPath = "Web Development";
careerColor="purple"
careerColor = "purple";
}
if (sessions[key].Name == "NET") {
careerPath = "Networking and Security";
careerColor="blue"
careerColor = "blue";
}
if (sessions[key].Name == "MOB") {
careerPath = "Mobile Development";
careerColor="orange"
careerColor = "orange";
}
if(sessions[key].Name=="DS"){
careerPath="Data Science"
careerColor="yellow"
if (sessions[key].Name == "DS") {
careerPath = "Data Science";
careerColor = "yellow";
}
}
return { name: careerPath, color: careerColor };
@ -169,8 +163,7 @@ export const connectionState = status => {
return { type: "CHANGE_CONNECTION_STATUS", isConnected: status };
};
//inscrição em palestra através de ID
export function signSession(token, idSession) {
export function removeSession(user,token, idSession) {
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
};
@ -183,9 +176,10 @@ export function signSession(token, idSession) {
return dispatch => {
//adiciona participante a uma palestra
axios
.post("/Session/AddAttendee", obj)
.post("/Session/RemoveAttendee", obj)
//se não existir erro na chamada...
.then(a => {
console.log(a)
if (a.data.Success) {
axios
.get("/Attendee/AvailableSessions")
@ -204,7 +198,7 @@ export function signSession(token, idSession) {
cenas.push(result[key]);
}
alert("Inscrição efectuada com sucesso");
Alert.alert("Sucesso","A inscrição na sessão foi removida com sucesso!");
//obter informações pessoais:
axios
@ -215,13 +209,14 @@ export function signSession(token, idSession) {
})
.then(sucess => {
dispatch({
type: SIGN_SESSION,
type: REMOVE_SESSION,
sessions: response.data,
Blocks: cenas,
changeGuestList: false,
careerPath: careerPath,
user: sucess.data
});
getEvents(user);
});
})
.catch(function(error) {
@ -230,9 +225,10 @@ export function signSession(token, idSession) {
console.log(error);
});
} else {
alert("Erro a inscrever na palestra");
dispatch({
type: SIGN_SESSION,
type: REMOVE_SESSION,
waitChangeGuest: false
});
}
@ -243,6 +239,82 @@ export function signSession(token, idSession) {
};
}
//inscrição em palestra através de ID
export function signSession(user,token, idSession) {
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
};
var obj = {
IdSession: idSession,
Direction: 0
};
return dispatch => {
//adiciona participante a uma palestra
axios
.post("/Session/AddAttendee", obj)
//se não existir erro na chamada...
.then(a => {
if (a.data.Success) {
axios
.get("/Attendee/AvailableSessions")
.then(function(response) {
console.log(response);
var sessions = response.data;
var careerPath = getCareerPath(sessions);
var cenas = [];
const result = flow(groupBy("SessionStart"))(response.data);
for (let key in result) {
result[key].option = 0;
cenas.push(result[key]);
}
Alert.alert("Sucesso","Inscrição na sessão efectuada com sucesso");
//obter informações pessoais:
axios
.get("/Attendee/Detail")
.catch(error => {
alert(error);
})
.then(sucess => {
dispatch({
type: SIGN_SESSION,
sessions: response.data,
Blocks: cenas,
changeGuestList: false,
careerPath: careerPath,
user: sucess.data
});
getEvents(user);
});
})
.catch(function(error) {
console.log(error);
});
} else {
Alert.alert("ERRO!!",a.data.Error);
dispatch({
type: SIGN_SESSION,
waitChangeGuest: false
});
}
})
.catch(b => {
// alert("Erro a inscrever na palestra");
});
};
}
export function getSessions(token) {
axios.defaults.headers.common = {
Authorization: `bearer ${token.access_token}`
@ -327,7 +399,6 @@ export function getAvailableGuestlists(token) {
*/
export function changeGuestList(token, guestID) {
//http://enei2019.uingress.com/internal/api/Attendee/ChangeGuestlist/
axios.defaults.headers.common = {
@ -340,7 +411,7 @@ export function changeGuestList(token, guestID) {
axios
.get(full)
.then(function(response) {
console.log(response)
console.log(response);
axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
axios.defaults.headers.common = {
@ -355,7 +426,7 @@ export function changeGuestList(token, guestID) {
//console.log(response);
var cenas = [];
c= getCareerPath(response.data);
c = getCareerPath(response.data);
const result = flow(
groupBy("SessionStart")
// map((Id) => ({Id})),
@ -463,10 +534,10 @@ export function getEvents(user) {
return dispatch => {
let events = [];
console.log("chegou aqui");
var i=0
var i = 0;
for (let key in user.Sessions) {
events.push({
key:i++,
key: i++,
time: moment(user.Sessions[key].SessionStart).format("HH:mm"),
timeEnd: moment(user.Sessions[key].SessionEnd).format("HH:mm"),
//lineColor:'#009688',
@ -479,48 +550,43 @@ var i=0
day: moment(user.Sessions[key].SessionStart).format("DD")
});
}
const result = flow(
groupBy("day")
)(events);
const result = flow(groupBy("day"))(events);
var cenas=[];
var cenas = [];
for (let key in result) {
cenas.push(result[key]);
console.log();
}
console.log(".--------")
console.log(".--------");
console.log(cenas);
console.log(".--------")
var a=[], b=[],c=[],d=[]
console.log(".--------");
var a = [],
b = [],
c = [],
d = [];
for (let key in cenas[0]) {
a.push({
time:cenas[0][key].time ,
time: cenas[0][key].time,
timeEnd: cenas[0][key].timeEnd,
imageUrl:cenas[0][key].imageUrl,
imageUrl: cenas[0][key].imageUrl,
description: cenas[0][key].description,
name:cenas[0][key].name,
name: cenas[0][key].name,
Enrolled: cenas[0][key].Enrolled,
MaxAttendees: cenas[0][key].MaxAttendees,
day: cenas[0][key].day
});
}
for (let key in cenas[1]) {
b.push({
time:cenas[1][key].time ,
time: cenas[1][key].time,
timeEnd: cenas[1][key].timeEnd,
imageUrl:cenas[1][key].imageUrl,
imageUrl: cenas[1][key].imageUrl,
description: cenas[1][key].description,
name:cenas[1][key].name,
name: cenas[1][key].name,
Enrolled: cenas[1][key].Enrolled,
MaxAttendees: cenas[1][key].MaxAttendees,
day: cenas[1][key].day
@ -528,11 +594,11 @@ var i=0
}
for (let key in cenas[2]) {
c.push({
time:cenas[2][key].time ,
time: cenas[2][key].time,
timeEnd: cenas[2][key].timeEnd,
imageUrl:cenas[2][key].imageUrl,
imageUrl: cenas[2][key].imageUrl,
description: cenas[2][key].description,
name:cenas[2][key].name,
name: cenas[2][key].name,
Enrolled: cenas[2][key].Enrolled,
MaxAttendees: cenas[2][key].MaxAttendees,
day: cenas[2][key].day
@ -541,29 +607,35 @@ var i=0
for (let key in cenas[3]) {
d.push({
time:cenas[3][key].time ,
time: cenas[3][key].time,
timeEnd: cenas[3][key].timeEnd,
imageUrl:cenas[3][key].imageUrl,
imageUrl: cenas[3][key].imageUrl,
description: cenas[3][key].description,
name:cenas[3][key].name,
name: cenas[3][key].name,
Enrolled: cenas[3][key].Enrolled,
MaxAttendees: cenas[3][key].MaxAttendees,
day: cenas[3][key].day
});
}
a=_.sortBy(a, function(o) { return o.time; });
b=_.sortBy(b, function(o) { return o.time; });
c=_.sortBy(c, function(o) { return o.time; });
d=_.sortBy(d, function(o) { return o.time; });
a = _.sortBy(a, function(o) {
return o.time;
});
b = _.sortBy(b, function(o) {
return o.time;
});
c = _.sortBy(c, function(o) {
return o.time;
});
d = _.sortBy(d, function(o) {
return o.time;
});
dispatch({
type: GET_EVENTS,
events:a,
day1:a,
day2:b,
day3:c,
day4:d
events: a,
day1: a,
day2: b,
day3: c,
day4: d
});
};
}
@ -653,54 +725,56 @@ export function login(user, pass) {
logged: false,
failedAttempt: true,
tokenData: "error",
user: { Name: "" },
user: { Name: "" }
});
})
.catch(err=>{
console.log("error")
.catch(err => {
console.log("error");
})
.then(res => res.json())
.then(parsed => {
console.log(parsed)
console.log(parsed);
if (
parsed.error_description ==
"Provided username and password is incorrect"
) {
Alert.alert("Dados Inválidos","Podes sempre fazer reset da password para o email.")
Alert.alert(
"Dados Inválidos",
"Podes sempre fazer reset da password para o email."
);
dispatch({
type: API_LOGIN,
logged: false,
failedAttempt: true,
token: obj,
user: { Name: "Henrique" },
userDetails:{},
waitLogin:false,
onHold:false
userDetails: {},
waitLogin: false,
onHold: false
});
return;
} else {
var obj = {
access_token: parsed.access_token,
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
refreshToken: parsed.refresh_token,
valid: true
};
var details = {
username: user,
password: pass
};
dispatch({
type: API_LOGIN,
logged: true,
failedAttempt: false,
token: obj,
user: { Name: "Henrique" },
userDetails: details
});
}
else{
var obj = {
access_token: parsed.access_token,
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
refreshToken: parsed.refresh_token,
valid: true
};
var details = {
username: user,
password: pass
};
dispatch({
type: API_LOGIN,
logged: true,
failedAttempt: false,
token: obj,
user: { Name: "Henrique" },
userDetails: details
});}
});
};
}

4
App/app/store/actions/index.js

@ -16,7 +16,9 @@ export {checkUser,
openModal,
closeModal,
loginInternal,
waitLogin
waitLogin,
removeSession
} from "./api"
export {

65
App/app/store/reducers/api.js

@ -15,8 +15,8 @@ import {
SIGN_SESSION,
OPEN_MODAL,
CLOSE_MODAL,
LOADINGLOGIN
LOADINGLOGIN,
REMOVE_SESSION
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
import { REHYDRATE } from "redux-persist";
@ -42,13 +42,12 @@ let apiState = {
sessions: {},
Blocks: {},
onHoldBlocks: true,
careerPath:{name:'Sem Career Path', color:'#eeeeee'},
a:{},
b:{},
c:{},
d:{},
loadingLogin:false,
careerPath: { name: "Sem Career Path", color: "#eeeeee" },
a: {},
b: {},
c: {},
d: {},
loadingLogin: false
};
const apiReducer = (state = apiState, action) => {
@ -101,7 +100,7 @@ const apiReducer = (state = apiState, action) => {
});
case LOADINGLOGIN:
state= Object.assign({}, state, {loadingLogin:true});
state = Object.assign({}, state, { loadingLogin: true });
case HOLD:
state = Object.assign({}, state, { onHold: true });
@ -118,7 +117,7 @@ const apiReducer = (state = apiState, action) => {
username: action.userDetails.username,
password: action.userDetails.password
},
loadingLogin:false,
loadingLogin: false,
onHold: action.onHold
});
@ -137,7 +136,11 @@ const apiReducer = (state = apiState, action) => {
return state;
case LOGOUT_USER:
state = Object.assign({}, state, { user:{}, userDetails:{}, logged:false});
state = Object.assign({}, state, {
user: {},
userDetails: {},
logged: false
});
return state;
@ -151,12 +154,28 @@ const apiReducer = (state = apiState, action) => {
return state;
case GET_EVENTS:
state = Object.assign({}, state, { events: action.events , a:action.day1, b:action.day2, c:action.day3, d:action.day4});
state = Object.assign({}, state, {
events: action.events,
a: action.day1,
b: action.day2,
c: action.day3,
d: action.day4
});
return state;
case REMOVE_SESSION:
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: action.changingGuest,
user: action.user
});
return state;
case OPEN_MODAL:
console.log("open modal")
console.log("open modal");
state = Object.assign({}, state, {
modalOpen: true,
modalInfo: action.modalInfo,
@ -173,13 +192,25 @@ const apiReducer = (state = apiState, action) => {
return state;
case SIGN_SESSION:
state = Object.assign({}, state, {
if(action.sessions==undefined || action.Blocks==undefined || action.user==undefined){
state = Object.assign({}, state, {
changingGuest: false,
});
}
else{
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: action.changingGuest,
user:action.user
changingGuest: false,
user: action.user
});
}
return state;
case SESSION_BLOCKS:

41
api/Controllers/AuthController.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Net.Http;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
@ -14,6 +15,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Linq;
namespace api.Controllers
{
@ -30,15 +32,18 @@ namespace api.Controllers
public IUsersRepository _repo { get; }
private readonly IMapper _mapper;
private readonly RoleManager<Role> _roleManager;
private readonly System.Net.Http.IHttpClientFactory clientFactory;
public AuthController(IConfiguration config, UserManager<User> UserManager, SignInManager<User> SignInManager, IMapper mapper, RoleManager<Role> roleManager, IUsersRepository repo)
public AuthController(IConfiguration config, UserManager<User> UserManager, SignInManager<User> SignInManager, IMapper mapper, RoleManager<Role> roleManager, IUsersRepository repo, System.Net.Http.IHttpClientFactory clientFactory)
{
_mapper = mapper;
_roleManager = roleManager;
_repo = repo;
this.clientFactory = clientFactory;
this.config = config;
_userManager = UserManager;
_signInManager = SignInManager;
}
@ -80,6 +85,40 @@ namespace api.Controllers
}
[HttpPost("loginQR")]
public async Task<IActionResult> loginQr(UserForLoginDto userLoginDTO){
var token= "_A6q1cVGa12QutCrYCsYETfz9nPspnbcnPqjD-87kDaYPr99ArEfpdRTbkEzA4p-WEJzPFQhsMX7nG5BmUm0E6RTju8vQHnaTjGd80NIqUCr-jXefUtGwyl6I00fGD4sN6psW714JnCFuZRbtZbIXsdIRKmD3b8YUpPo2lvYP8SzjoEgACyabj13T3CLpHF43PI8Dvny6ylW6j0ka5qGNvw5MHVvYFURUPiTA7hlxoyQ35eOqHE8-eIiLNSTUJW7q-o8CxIGqGWSkltKPxbrY-Xo5iYagUucesqmj64VxYs";
using (var client = new HttpClient())
{
try{
var url = "http://enei2019.uingress.com/internal/api/Attendee/Detail";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
var response = await client.GetStringAsync(url);
Console.WriteLine(response);
//var resource = JObject.Parse(response);
return Ok(response);
}catch(Exception e){
Console.WriteLine(e);
return Unauthorized();
}
}
}
private async Task<string> GenerateJwtToken(User user)
{
var claims = new List<Claim>

23
api/Dtos/tokenDto.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using api.Models;
namespace api.Dtos
{
public class tokenDto
{
public string access_token{get;set;} //teamid
public string token_type{get;set;} //user qr
public int expires_in{get;set;}
public string refresh_token{get;set;}
}
}

18
api/Dtos/userDetails.cs

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using api.Models;
namespace api.Dtos
{
public class userDetails
{
public string name{get;set;} //teamid
public string qr{get;set;} //user qr
}
}

2
api/Startup.cs

@ -42,7 +42,7 @@ namespace api
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
services.AddAutoMapper();
services.AddScoped<IUsersRepository, UsersRepository>();
services.AddScoped<IEventsRepository, EventsRepository>();

11
api/api.csproj

@ -3,12 +3,13 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\"/>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
</ItemGroup>
</Project>

2
api/obj/Debug/netcoreapp2.1/project.razor.json

@ -1,5 +1,5 @@
{
"ProjectFilePath": "c:\\Users\\ZMiguel\\Desktop\\ENEI2019\\api\\api.csproj",
"ProjectFilePath": "/Users/henrique/ENEI2019/api/api.csproj",
"TargetFramework": "netcoreapp2.1",
"TagHelpers": [],
"Configuration": {

Loading…
Cancel
Save