Ejemplo n.º 1
0
 public FacebookIdentity(User user)
 {
     this.Name = user.Name;
     this.Id = user.Id;
     this.Token = user.Token;
     this.Roles = user.Roles != null ? user.Roles.ToArray() : new string[] { };
     this.PlaceRoles = user.PlaceRoles != null ? user.PlaceRoles.ToArray() : new List<Tuple<int, string>>().ToArray();
 }
Ejemplo n.º 2
0
        public void Update(User user)
        {
            var userEntity = _context.Users.Where(u => u.Id == user.Id).ToList().First();

            userEntity.Name = user.Name;
            userEntity.FirstName = user.FirstName;
            userEntity.LastName = user.LastName;
            userEntity.UserName = user.UserName;
            userEntity.Email = user.Email;
            userEntity.Birthday = user.Birthday;
            userEntity.Token = user.Token;
            userEntity.Created = user.Created;
            userEntity.LastLogin = user.LastLogin;

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public void Login(string token)
        {
            try
            {
                if (this.User != null && this.User.Token == token) return;

                _authentication.SetToken(token);
                HttpContext.Current.Session.Remove("Places");
                this.User = _authentication.GetUser();

                HttpContext.Current.Response.Cookies["user"]["id"] = this.User.Id.ToString();
                HttpContext.Current.Response.Cookies["user"]["token"] = this.User.Token;
            }
            catch
            {
                this.User = null;
                HttpContext.Current.Session.Remove("Places");
                FormsAuthentication.SignOut();

                throw new UnauthorizedAccessException("Invalid token");
            }
        }
Ejemplo n.º 4
0
        public void Add(User user)
        {
            var userEntity = new UserEntity
            {
                Id = user.Id,
                Name = user.Name,
                FirstName = user.FirstName,
                LastName = user.LastName,
                UserName = user.UserName,
                Email = user.Email,
                Birthday = user.Birthday,
                Token = user.Token,
                Created = DateTime.Now,
                LastLogin = DateTime.Now,
            };

            _context.Users.AddObject(userEntity);
            _context.SaveChanges();

            user.Id = userEntity.Id;
            user.Created = userEntity.Created;
            user.LastLogin = userEntity.LastLogin;
        }
Ejemplo n.º 5
0
        public User GetUser()
        {
            if (this.Client == null) throw new InvalidOperationException("Client not initialized.");

            DateTime bd = DateTime.Now;
            var user = this.Client.Get("me") as dynamic;
            var userDto = new User
            {
                Id = Convert.ToInt64(user.id),
                Name = user.name,
                UserName = user.username,
                FirstName = user.first_name,
                LastName = user.last_name,
                Email = user.email,
                Token = this.Token,
            };

            if (user.birthday != null && DateTime.TryParse(user.birthday, FacebookCulture.DateTimeFormat, DateTimeStyles.None, out bd))
                userDto.Birthday = bd;
            else
                userDto.Birthday = null;

            return userDto;
        }
Ejemplo n.º 6
0
 public void Logout()
 {
     this.User = null;
     HttpContext.Current.Response.Cookies["user"].Expires = DateTime.Now.AddDays(-1D);
     HttpContext.Current.Session.Remove("Places");
     FormsAuthentication.SignOut();
 }
Ejemplo n.º 7
0
 private void Delete(User user)
 {
     _context.Users.DeleteObject(new UserEntity { Id = user.Id });
     _context.SaveChanges();
 }