Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
245 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
namespace Trady.Models | ||
{ | ||
public class FacebookProfile | ||
{ | ||
public string Name { get; set; } | ||
public Picture Picture { get; set; } | ||
public string Id { get; set; } | ||
|
||
} | ||
|
||
public class Picture | ||
{ | ||
public Data Data { get; set; } | ||
} | ||
|
||
public class Data | ||
{ | ||
public bool IsSilhouette { get; set; } | ||
public string Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace Trady.Views | ||
{ | ||
public partial class MainPage : ContentPage | ||
|
||
{ | ||
|
||
public MainPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
async void Fbbtn_Clicked(System.Object sender, System.EventArgs e) | ||
{ | ||
|
||
await Navigation.PushAsync(new facebookLoginPage()); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace Trady.Views | ||
{ | ||
public partial class RecievedOfferPage : ContentPage | ||
{ | ||
public RecievedOfferPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
async void acceptbtn_Clicked(System.Object sender, System.EventArgs e) | ||
{ | ||
await Navigation.PushAsync(new MyTradesPage()); | ||
} | ||
|
||
async void declinebtn_Clicked(System.Object sender, System.EventArgs e) | ||
{ | ||
await Navigation.PushAsync(new MyTradesPage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace Trady.Views | ||
{ | ||
public partial class SubmitOfferPage : ContentPage | ||
{ | ||
public SubmitOfferPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
async void submitOfferbtn_Clicked(System.Object sender, System.EventArgs e) | ||
{ | ||
await Navigation.PushAsync(new MyTradesPage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Trady.Views.facebookLoginPage"> | ||
<ContentPage.Content> | ||
|
||
|
||
<WebView x:Name="WebView" HeightRequest="10" WidthRequest="10" VerticalOptions="FillAndExpand"/> | ||
|
||
</ContentPage.Content> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using Newtonsoft.Json; | ||
using Xamarin.Forms; | ||
using Trady.Models; | ||
using SQLite; | ||
|
||
namespace Trady.Views | ||
{ | ||
public partial class facebookLoginPage : ContentPage | ||
{ | ||
|
||
//private string ClientId = "1272538809769102"; | ||
|
||
public facebookLoginPage() | ||
|
||
|
||
{ | ||
InitializeComponent(); | ||
|
||
WebView.Source = "https://www.facebook.com/v9.0/dialog/oauth?client_id=1272538809769102&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token"; | ||
WebView.Navigated += WebView_Navigated; | ||
|
||
|
||
} | ||
private void WebView_Navigated(object sender, WebNavigatedEventArgs e) | ||
{ | ||
var AccessURL = e.Url; | ||
if (AccessURL.Contains("access_token")) | ||
{ | ||
AccessURL = AccessURL.Replace("https://www.facebook.com/connect/login_success.html#access_token=", string.Empty); | ||
var accessToken = AccessURL.Split('&')[0]; | ||
HttpClient client = new HttpClient(); | ||
var response = client.GetStringAsync("https://graph.facebook.com/me?fields=name,picture,email,id&access_token=" + accessToken).Result; | ||
|
||
|
||
var Data = JsonConvert.DeserializeObject<FacebookProfile>(response); | ||
|
||
|
||
//connecto to database to check if user is already registered | ||
using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) | ||
{ | ||
|
||
|
||
conn.Delete<User>(13); | ||
var beforCurrentActiveUsers = conn.Table<User>().Where(r => r.CurrentUser == false); | ||
var loggedInUser = conn.Table<User>().FirstOrDefault(c => c.FacebookId == Data.Id); | ||
|
||
if(loggedInUser == null) | ||
{ | ||
|
||
// Adding user to database | ||
User user = new User() | ||
{ | ||
Name = Data.Name, | ||
//email = Data.email, | ||
Picture = Data.Picture.Data.Url, | ||
FacebookId = Data.Id, | ||
CurrentUser= false | ||
|
||
}; | ||
|
||
// establishin connection to database | ||
conn.CreateTable<User>(); | ||
int rowsAdded = conn.Insert(user); | ||
|
||
} | ||
|
||
var activeUser = conn.Table<User>().FirstOrDefault(c => c.FacebookId == Data.Id); | ||
conn.Update(new User { | ||
UserId = activeUser.UserId, | ||
CurrentUser = true, | ||
FacebookId = activeUser.FacebookId, | ||
Name = activeUser.Name, | ||
Offers = activeUser.Offers, | ||
Picture = activeUser.Picture, | ||
Trades = activeUser.Trades | ||
|
||
}); | ||
|
||
var beforeCurrentActiveUsers = conn.Table<User>().First(r => r.CurrentUser == true); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
Navigation.PushAsync(new MyTradesPage()); | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
} | ||
} |