public Authentication Login(LoginCredentials credentials) { var result = new Authentication(); var facebookCredentials = credentials as FacebookLoginCredentials; if (facebookCredentials != null) { var facebookSession = new Facebook.FacebookClient(facebookCredentials.AccessToken); dynamic me = facebookSession.Get("me"); var facebookUser = new FacebookUser { FacebookUserId = long.Parse(me["id"]), UserName = me["username"] }; result.UserId = _data.CheckOrInsertFacebookUser(facebookUser); var session = StartSession(result.UserId); result.Ticket = session.Key; result.ValidTill = session.Value; return result; } throw new NotImplementedException("Only facebook users are supported now"); }
public long CheckOrInsertFacebookUser(FacebookUser user) { var existingUser = _data.Users.SingleOrDefault(s => s.facebookId == user.FacebookUserId); if (existingUser == null) return InsertUser(user); else return existingUser.userId; }
public long CheckOrInsertFacebookUser(FacebookUser user) { long id = 0; if (_users.Any()) id = _users.Max(s => s.UserId) + 1; user.UserId = id; _users.Add(user); return user.UserId; }