Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2aca01f

Browse files
committed
Grab some more user data from fb.
1 parent 2e1fb86 commit 2aca01f

14 files changed

+31
-9
lines changed

‎src/Controllers/DashboardController.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public async Task<IActionResult> Home()
4141
customer.Identity.FirstName,
4242
customer.Identity.LastName,
4343
customer.Identity.PictureUrl,
44-
customer.Identity.FacebookId
44+
customer.Identity.FacebookId,
45+
customer.Location,
46+
customer.Locale,
47+
customer.Gender
4548
});
4649
}
4750
}

‎src/Controllers/ExternalAuthController.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task<IActionResult> Facebook([FromBody]FacebookAuthViewModel model)
5353
}
5454

5555
// 3. we've got a valid token so we can request user data from fb
56-
var userInfoResponse = await Client.GetStringAsync($"https://graph.facebook.com/v2.8/me?fields=id,email,first_name,last_name,name,gender,birthday,picture&access_token={model.AccessToken}");
56+
var userInfoResponse = await Client.GetStringAsync($"https://graph.facebook.com/v2.8/me?fields=id,email,first_name,last_name,name,gender,locale,birthday,picture&access_token={model.AccessToken}");
5757
var userInfo = JsonConvert.DeserializeObject<FacebookUserData>(userInfoResponse);
5858

5959
// 4. ready to create the local user account (if necessary) and jwt
@@ -75,7 +75,7 @@ public async Task<IActionResult> Facebook([FromBody]FacebookAuthViewModel model)
7575

7676
if (!result.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState));
7777

78-
await _appDbContext.Customers.AddAsync(new Customer { IdentityId = appUser.Id, Location = ""});
78+
await _appDbContext.Customers.AddAsync(new Customer { IdentityId = appUser.Id, Location = "",Locale=userInfo.Locale,Gender=userInfo.Gender});
7979
await _appDbContext.SaveChangesAsync();
8080
}
8181

‎src/Migrations/20180103200309_initial.Designer.cs‎ renamed to ‎src/Migrations/20180104134211_initial.Designer.cs‎

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/Migrations/20180103200309_initial.cs‎ renamed to ‎src/Migrations/20180104134211_initial.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
164164
{
165165
Id = table.Column<int>(type: "int", nullable: false)
166166
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
167+
Gender = table.Column<string>(type: "nvarchar(max)", nullable: true),
167168
IdentityId = table.Column<string>(type: "nvarchar(450)", nullable: true),
169+
Locale = table.Column<string>(type: "nvarchar(max)", nullable: true),
168170
Location = table.Column<string>(type: "nvarchar(max)", nullable: true)
169171
},
170172
constraints: table =>

‎src/Migrations/ApplicationDbContextModelSnapshot.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
8484
b.Property<int>("Id")
8585
.ValueGeneratedOnAdd();
8686

87+
b.Property<string>("Gender");
88+
8789
b.Property<string>("IdentityId");
8890

91+
b.Property<string>("Locale");
92+
8993
b.Property<string>("Location");
9094

9195
b.HasKey("Id");

‎src/Models/Entities/Customer.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22

33
namespace AngularASPNETCore2WebApiAuth.Models.Entities
44
{
@@ -8,5 +8,7 @@ public class Customer
88
public string IdentityId { get; set; }
99
public AppUser Identity { get; set; } // navigation property
1010
public string Location { get; set; }
11+
public string Locale { get; set; }
12+
public string Gender { get; set; }
1113
}
1214
}

‎src/Models/FacebookApiResponses.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal class FacebookUserData
1313
[JsonProperty("last_name")]
1414
public string LastName { get; set; }
1515
public string Gender { get; set; }
16+
public string Locale { get; set; }
1617
public FacebookPictureData Picture { get; set; }
1718
}
1819

‎src/src/app/dashboard/home/home.component.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11

22
<div class="row">
3-
<div class="col-md-6 col-sm-3 placeholder">
3+
<div class="col-md-6 col-sm-3">
44
<p>{{homeDetails?.message}}</p>
55
<p><strong>Name:</strong> {{homeDetails?.firstName}} {{homeDetails?.lastName}}</p>
6+
<p *ngIf="homeDetails?.location"><strong>Location:</strong> {{homeDetails?.location}}</p>
7+
<p *ngIf="homeDetails?.locale"><strong>Locale:</strong> {{homeDetails?.locale}}</p>
8+
<p *ngIf="homeDetails?.gender"><strong>Gender:</strong> {{homeDetails?.gender}}</p>
69
<p *ngIf="homeDetails?.facebookId"><strong>Facebook Id:</strong> {{homeDetails?.facebookId}}</p>
710
<div *ngIf="homeDetails?.pictureUrl"><img src="{{homeDetails?.pictureUrl}}" /></div>
811
</div>

‎src/src/app/dashboard/models/home.details.interface.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export interface HomeDetails {
22
message: string;
33
firstName: string;
44
lastName: string;
5+
location: string;
6+
locale: string;
7+
gender: string;
58
pictureUrl: string;
69
facebookId: number;
710
}

‎src/wwwroot/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><title>JwtAuthDemo</title><base href="/"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.053af3a4d85fe061870e.bundle.css" rel="stylesheet"/></head><body><app-root>Loading...</app-root><script type="text/javascript" src="inline.a4b4e69e115138ee47a9.bundle.js"></script><script type="text/javascript" src="polyfills.61df7d7ec492d95bb0b2.bundle.js"></script><script type="text/javascript" src="main.941c311027417c61f16c.bundle.js"></script></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><title>JwtAuthDemo</title><base href="/"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.053af3a4d85fe061870e.bundle.css" rel="stylesheet"/></head><body><app-root>Loading...</app-root><script type="text/javascript" src="inline.b6708a750e679a974885.bundle.js"></script><script type="text/javascript" src="polyfills.61df7d7ec492d95bb0b2.bundle.js"></script><script type="text/javascript" src="main.1aad2c23f74b94cefc12.bundle.js"></script></body></html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /