Commit 58c67684 authored by Robert Czechowski's avatar Robert Czechowski

Use oauth_provider_id to differentiate between different oauth providers

parent e51c3686
Pipeline #399 passed with stage
in 7 minutes and 41 seconds
UPDATE session SET oauth_provider = "pms" WHERE oauth_foreign_id IS NOT NULL;
UPDATE session_user SET oauth_provider = "pms" WHERE oauth_foreign_id IS NOT NULL;
UPDATE session SET oauth_provider = "pms" WHERE oauth_foreign_id IS NOT NULL;
......@@ -1004,9 +1004,10 @@ pub struct ForeignUserData {
pub lastname: String,
}
pub fn login_oauth<T: MedalConnection>(conn: &T, user_data: ForeignUserData)
pub fn login_oauth<T: MedalConnection>(conn: &T, user_data: ForeignUserData, oauth_provider_id: String)
-> Result<String, (String, json_val::Map<String, json_val::Value>)> {
match conn.login_foreign(None,
&oauth_provider_id,
&user_data.foreign_id,
user_data.foreign_type != UserType::User,
&user_data.firstname,
......
......@@ -411,7 +411,7 @@ impl MedalConnection for Connection {
}
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str,
fn login_foreign(&self, _session: Option<&str>, provider_id: &str, foreign_id: &str, is_teacher: bool, firstname: &str,
lastname: &str)
-> Result<String, ()>
{
......@@ -421,8 +421,9 @@ impl MedalConnection for Connection {
let query = "SELECT id
FROM session
WHERE oauth_foreign_id = $1";
match self.query_map_one(query, &[&foreign_id], |row| -> i32 { row.get(0) }) {
WHERE oauth_foreign_id = $1
AND oauth_provider = $2";
match self.query_map_one(query, &[&foreign_id, &provider_id], |row| -> i32 { row.get(0) }) {
Ok(Some(id)) => {
let query = "UPDATE session
SET session_token = $1, csrf_token = $2, last_login = $3, last_activity = $3
......@@ -435,8 +436,8 @@ impl MedalConnection for Connection {
_ => {
let query = "INSERT INTO session (session_token, csrf_token, last_login, last_activity,
permanent_login, grade, is_teacher, oauth_foreign_id,
firstname, lastname)
VALUES ($1, $2, $3, $3, $4, $5, $6, $7, $8, $9)";
oauth_provider, firstname, lastname)
VALUES ($1, $2, $3, $3, $4, $5, $6, $7, $8, $9, $10)";
self.execute(query,
&[&session_token,
&csrf_token,
......@@ -445,6 +446,7 @@ impl MedalConnection for Connection {
&(if is_teacher {255} else {0}),
&is_teacher,
&foreign_id,
&provider_id,
&firstname,
&lastname])
.unwrap();
......
......@@ -18,7 +18,8 @@ pub trait MedalConnection {
fn login(&self, session: Option<&str>, username: &str, password: &str) -> Result<String, ()>;
fn login_with_code(&self, session: Option<&str>, logincode: &str) -> Result<String, ()>;
fn login_foreign(&self, session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str, lastname: &str)
fn login_foreign(&self, session: Option<&str>, provider_id: &str, foreign_id: &str, is_teacher: bool,
firstname: &str, lastname: &str)
-> Result<String, ()>;
fn create_user_with_groupcode(&self, session: Option<&str>, groupcode: &str) -> Result<String, ()>;
fn create_group_with_users(&self, group: Group);
......
......@@ -507,8 +507,8 @@ impl MedalConnection for Connection {
}
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str,
lastname: &str)
fn login_foreign(&self, _session: Option<&str>, provider_id: &str, foreign_id: &str, is_teacher: bool,
firstname: &str, lastname: &str)
-> Result<String, ()>
{
let session_token = helpers::make_session_token();
......@@ -517,8 +517,9 @@ impl MedalConnection for Connection {
let query = "SELECT id
FROM session
WHERE oauth_foreign_id = $1";
match self.query_map_one(query, &[&foreign_id], |row| -> i32 { row.get(0) }) {
WHERE oauth_foreign_id = $1
AND oauth_provider = $2";
match self.query_map_one(query, &[&foreign_id, &provider_id], |row| -> i32 { row.get(0) }) {
Ok(Some(id)) => {
let query = "UPDATE session
SET session_token = $1, csrf_token = $2, last_login = $3, last_activity = $3
......@@ -531,8 +532,8 @@ impl MedalConnection for Connection {
_ => {
let query = "INSERT INTO session (session_token, csrf_token, last_login, last_activity,
permanent_login, grade, is_teacher, oauth_foreign_id,
firstname, lastname)
VALUES ($1, $2, $3, $3, $4, $5, $6, $7, $8, $9)";
oauth_provider, firstname, lastname)
VALUES ($1, $2, $3, $3, $4, $5, $6, $7, $8, $9, $10)";
self.execute(query,
&[&session_token,
&csrf_token,
......@@ -541,6 +542,7 @@ impl MedalConnection for Connection {
&(if is_teacher { 255 } else { 0 }),
&is_teacher,
&foreign_id,
&provider_id,
&firstname,
&lastname])
.unwrap();
......
......@@ -494,8 +494,8 @@ impl MedalConnection for Connection {
}
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str,
lastname: &str)
fn login_foreign(&self, _session: Option<&str>, provider_id: &str, foreign_id: &str, is_teacher: bool,
firstname: &str, lastname: &str)
-> Result<String, ()>
{
let session_token = helpers::make_session_token();
......@@ -504,8 +504,9 @@ impl MedalConnection for Connection {
let query = "SELECT id
FROM session_user
WHERE oauth_foreign_id = ?1";
match self.query_map_one(query, &[&foreign_id], |row| -> i32 { row.get(0) }) {
WHERE oauth_foreign_id = ?1
AND oauth_provider = ?2";
match self.query_map_one(query, &[&foreign_id, &provider_id], |row| -> i32 { row.get(0) }) {
Ok(Some(id)) => {
let query = "UPDATE session_user
SET session_token = ?1, csrf_token = ?2, last_login = ?3, last_activity = ?3
......@@ -518,8 +519,8 @@ impl MedalConnection for Connection {
_ => {
let query = "INSERT INTO session_user (session_token, csrf_token, last_login, last_activity,
permanent_login, grade, is_teacher, oauth_foreign_id,
firstname, lastname)
VALUES (?1, ?2, ?3, ?3, ?4, ?5, ?6, ?7, ?8, ?9)";
oauth_provider, firstname, lastname)
VALUES (?1, ?2, ?3, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
self.execute(query,
&[&session_token,
&csrf_token,
......@@ -528,6 +529,7 @@ impl MedalConnection for Connection {
&(if is_teacher { 255 } else { 0 }),
&is_teacher,
&foreign_id,
&provider_id,
&firstname,
&lastname])
.unwrap();
......
......@@ -507,8 +507,8 @@ impl MedalConnection for Connection {
}
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str,
lastname: &str)
fn login_foreign(&self, _session: Option<&str>, provider_id: &str, foreign_id: &str, is_teacher: bool,
firstname: &str, lastname: &str)
-> Result<String, ()>
{
let session_token = helpers::make_session_token();
......@@ -517,8 +517,9 @@ impl MedalConnection for Connection {
let query = "SELECT id
FROM session
WHERE oauth_foreign_id = ?1";
match self.query_map_one(query, &[&foreign_id], |row| -> i32 { row.get(0) }) {
WHERE oauth_foreign_id = ?1
AND oauth_provider = ?2";
match self.query_map_one(query, &[&foreign_id, &provider_id], |row| -> i32 { row.get(0) }) {
Ok(Some(id)) => {
let query = "UPDATE session
SET session_token = ?1, csrf_token = ?2, last_login = ?3, last_activity = ?3
......@@ -531,8 +532,8 @@ impl MedalConnection for Connection {
_ => {
let query = "INSERT INTO session (session_token, csrf_token, last_login, last_activity,
permanent_login, grade, is_teacher, oauth_foreign_id,
firstname, lastname)
VALUES (?1, ?2, ?3, ?3, ?4, ?5, ?6, ?7, ?8, ?9)";
oauth_provider, firstname, lastname)
VALUES (?1, ?2, ?3, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
self.execute(query,
&[&session_token,
&csrf_token,
......@@ -541,6 +542,7 @@ impl MedalConnection for Connection {
&(if is_teacher { 255 } else { 0 }),
&is_teacher,
&foreign_id,
&provider_id,
&firstname,
&lastname])
.unwrap();
......
......@@ -915,7 +915,7 @@ fn oauth<C>(req: &mut Request) -> IronResult<Response>
let conn = mutex.lock().unwrap_or_else(|e| e.into_inner());
// Antwort erstellen und zurücksenden
core::login_oauth(&*conn, user_data)
core::login_oauth(&*conn, user_data, oauth_id)
/*let mut data = json_val::Map::new();
data.insert("reason".to_string(), to_json(&"Not implemented".to_string()));
("profile", data)*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment