コード例 #1
0
ファイル: TransitPostLogin.cs プロジェクト: dblock/dblog
 public TransitPostLogin(ISession session, DBlog.Data.PostLogin o)
     : base(o.Id)
 {
     Post = new TransitPost(session, o.Post, false);
     Login = new TransitLogin(o.Login);
 }
コード例 #2
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
        public int CreateOrUpdatePostLogin(string ticket, int post_id, TransitLogin t_login)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                CheckAdministrator(session, ticket);

                Post post = (Post)session.Load(typeof(Post), post_id);

                Login login = t_login.GetLogin(session);
                session.SaveOrUpdate(login);

                PostLogin post_login = session.CreateCriteria(typeof(PostLogin))
                    .Add(Expression.Eq("Post.Id", post_id))
                    .Add(Expression.Eq("Login.Id", t_login.Id))
                    .UniqueResult<PostLogin>();

                if (post_login == null)
                {
                    post_login = new PostLogin();
                    post_login.Post = post;
                    post_login.Login = login;
                    session.SaveOrUpdate(post_login);
                }

                session.Flush();
                return login.Id;
            }
        }
コード例 #3
0
 public TransitPostLogin(ISession session, DBlog.Data.PostLogin o)
     : base(o.Id)
 {
     Post  = new TransitPost(session, o.Post, false);
     Login = new TransitLogin(o.Login);
 }
コード例 #4
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
        public int CreateOrUpdateLogin(string ticket, TransitLogin t_login)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                Login login = t_login.GetLogin(session);

                if (!ManagedLogin.IsAdministrator(session, ticket) && t_login.Role == TransitLoginRole.Administrator)
                {
                    throw new ManagedLogin.AccessDeniedException();
                }

                if (ManagedLogin.IsAdministrator(session, ticket))
                {
                    if (t_login.Role != TransitLoginRole.Administrator && t_login.Id == ManagedLogin.GetLoginId(ticket))
                    {
                        // check whether self and administrator
                        throw new InvalidOperationException("Cannot Demote Self");
                    }
                }

                // find an existing login, if any
                Login existingLogin = session.CreateCriteria(typeof(Login))
                        .Add(Expression.Eq("Username", login.Username))
                        .Add(Expression.Not(Expression.Eq("Id", login.Id)))
                        .UniqueResult<Login>();

                if (existingLogin != null)
                {
                    throw new Exception(string.Format("A user registered with e-mail {0} already exists. Please choose a different one.",
                        login.Email));
                }

                session.SaveOrUpdate(login);
                session.Flush();
                return login.Id;
            }
        }