Esempio n. 1
0
 protected User CreateMockUser(string name)
 {
     var user = new User {
         Id= Guid.NewGuid(),
         UserName= name
     };
     mockUsersRepo.Setup(d => d.Get(user.Id)).Returns(user);
     mockUsersRepo.Setup(d => d.GetUserFromIdentifier(user.Id)).Returns(user);
     mockUsersRepo.Setup(d => d.FindBy(It.IsAny<Expression<Func<User,bool>>>())).Returns(new [] { user }.AsQueryable());
     return user;
 }
Esempio n. 2
0
        private static User NewUser(dynamic user)
        {
            var author = new User
            {
                Id = Guid.NewGuid(),
                UserName = user.name,
            };

            if (user.avatar_url != null)
            {
                string avatar = user.avatar_url;
                if (avatar.Contains("&"))
                    avatar = avatar.Substring(0, avatar.IndexOf("&"));
                author.AvatarUrl = avatar;
            }
            return author;
        }
Esempio n. 3
0
        public LoginModule(IUserRepository userRepository)
        {
            _user = userRepository;

            Post["/login/token"] = x =>
            {
                if (string.IsNullOrWhiteSpace(Request.Form.token))
                    return
                        View["Login/Error",
                            new
                                {
                                    Title = "Login Error",
                                    Message = "Bad response from login provider - could not find login token."
                                }];

                var response = new WebClient().DownloadString(string.Format("https://rpxnow.com/api/v2/auth_info?apiKey={0}&token={1}",apikey, Request.Form.token));

                if (string.IsNullOrWhiteSpace(response))
                    return
                        View["Login/Error",
                            new
                                {
                                    Title = "Login Error",
                                    Message = "Bad response from login provider - could not find user."
                                }];

                var j = JsonConvert.DeserializeObject<dynamic>(response);

                if (j.stat.ToString() != "ok")
                    return
                        View["Login/Error",
                            new
                                {
                                    Title = "Login Error",
                                    Message = "Bad response from login provider."
                                }];

                var userIdentity = j.profile.identifier.ToString();
                var username = j.profile.preferredUsername.ToString();
                string email = string.Empty;
                if (j.profile.email != null)
                    email = j.profile.email.ToString();
                var user = _user.GetUserFromUserIdentity(userIdentity);

                if (user == null)
                {
                    var u = new User
                                {
                                    Id = Guid.NewGuid(),
                                    Identity = userIdentity,
                                    UserName = (!string.IsNullOrEmpty(username)) ? username : "******" + _user.GetAll().Count(),
                                    Email = (!string.IsNullOrEmpty(email)) ? email : "*****@*****.**",
                                    Github = (!string.IsNullOrEmpty(username)) ? username : "",
                                    IsActive = true,
                                };

                    if (!_user.GetAll().Any())
                        _user.AddRole(u, "Admin");

                    if (j.profile.photo != null)
                        u.AvatarUrl = j.profile.photo.ToString();

                    _user.Add(u);
                    return this.LoginAndRedirect(u.Id, DateTime.Now.AddDays(1), "/profile/edit");
                }

                return ModuleExtensions.Login(this, user.Id, DateTime.Now.AddDays(1), "/");
            };

            Get["/logout/"] = parameters => this.LogoutAndRedirect("/");
        }
 public virtual void Edit(User entity)
 {
     _entities.Entry(entity).State = System.Data.EntityState.Modified;
     _entities.SaveChanges();
 }
 public virtual void Add(User entity)
 {
     _entities.Set<User>().Add(entity);
     _entities.SaveChanges();
 }