Beispiel #1
0
        public SeerefineIdentity(Login login, User user)
        {
            UserName = login.Username;
            Claims = login.Roles.Select(x => x.ToString()).ToArray();
            ClientId = login.ClientId;
            Teams = new List<Tuple<string, string>>();

            if (user != null)
            {
                Teams = new List<Tuple<string, string>>()
                    {
                        Tuple.Create(user.TeamId, user.TeamName),
                    };
            }
        }
        public ManageUsersModule(ISessionProvider sessionProvider, IDispatchEvents eventDispatcher)
            : base(sessionProvider, eventDispatcher, "/manage/clients/{id}")
        {
            Get["/users/create"] = parameters => View["views/manage/_createUser.html", new {ClientId}];

            Get["/users/list"] = parameters =>
                {
                    var users = RavenSession.Query<User>()
                                            .Where(x => x.ClientId == ClientId)
                                            .ToList();

                    var viewModel = new
                        {
                            data = users.Select(x => new {title = x.Id, content = x.Name}),
                        };

                    return Response.AsJson(viewModel);
                };

            Get["/users/wihtoutteam"] = parameters =>
                {
                    var users = RavenSession.Query<User>()
                                            .Where(x => x.ClientId == ClientId && x.TeamId == null);

                    return Response.AsJson(users);
                };

            Post["/users/create"] = parameters =>
                {

                    var command = this.Bind<CreateLoginCommand>();

                    if (command.AuthenticationKey == Guid.Empty)
                        command.AuthenticationKey = Guid.NewGuid();

                    var login = new Login
                        {
                            AuthenticationKey = command.AuthenticationKey,
                            ClientId = ClientId,
                            Username = command.UserName,
                            Password = command.Password,
                            Roles = new List<Roles> {Roles.ClientUser},
                        };

                    RavenSession.Store(login);

                    var user = new User
                        {
                            ClientId = ClientId,
                            Name = Request.Form["Name"],
                            LoginId = login.Id,
                        };

                    RavenSession.Store(user);

                    RavenSession.Store(new UserNameAndPasswordIsUnique
                        {
                            Id = command.ToUniqueString(),
                            AuthenticationKey = command.AuthenticationKey,
                        });

                    RavenSession.SaveChanges();

                    return HttpStatusCode.NoContent;
                };
        }