示例#1
0
        /// <summary>
        /// 根据对象实体数据新增一个用户
        /// </summary>
        /// <param name="account">登录账号</param>
        /// <param name="user">用户对象</param>
        /// <returns>JsonResult</returns>
        public JsonResult AddUser(string account, SYS_User user)
        {
            const string action = "60D5BE64-0102-4189-A999-96EDAD3DA1B5";
            var          verify = new SessionVerify();

            // 用户注册,验证用户签名
            if (verify.Basis == null)
            {
                var session = verify.Session;
                var sign    = Hash(session.LoginName + user.LoginName + user.Password);
                if (sign != session.Signature)
                {
                    return(verify.Result.InvalidAuth());
                }

                if (!InsertData(user))
                {
                    return(verify.Result.DataBaseError());
                }

                // 返回用于验证的Key
                session.Signature = Hash(account.ToUpper() + user.Password);
                session           = SessionManage.GetSession(session);
                return(verify.Result.Created(CreateKey(session)));
            }

            // 管理员添加用户,验证管理员身份及鉴权
            if (!verify.Compare(action))
            {
                return(verify.Result);
            }

            return(InsertData(user) ? verify.Result.Created() : verify.Result.DataBaseError());
        }
示例#2
0
        /// <summary>
        /// 更新指定用户Session的签名
        /// </summary>
        /// <param name="account">登录账号</param>
        /// <param name="password">新密码</param>
        /// <returns>JsonResult</returns>
        public JsonResult UpdateSignature(string account, string password)
        {
            const string action  = "26481E60-0917-49B4-BBAA-2265E71E7B3F";
            var          verify  = new SessionVerify();
            var          session = verify.Basis;

            if (!StringCompare(session.LoginName, account))
            {
                session = SessionManage.GetSession(account);
            }

            if (!verify.Compare(action, account))
            {
                return(verify.Result);
            }

            var reset = Update(account, password);

            if (!reset.HasValue)
            {
                return(verify.Result.NotFound());
            }

            if (!reset.Value)
            {
                return(verify.Result.DataBaseError());
            }

            if (session == null)
            {
                return(verify.Result);
            }

            session.Signature = Hash(session.LoginName.ToUpper() + password);
            return(verify.Result.Success(CreateKey(session)));
        }