示例#1
0
        /// <summary>
        /// Delete user from team.
        /// </summary>
        /// <param name="userId">User id.</param>
        /// <param name="teamId">Team id.</param>
        /// <returns></returns>
        public Task <string> DeleteUser(int userId, int teamId)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var teamWithUser = context.TeamWithUsers.ToList().Find(t => t.TeamId == teamId && t.UserId == userId);
                    if (teamWithUser == null)
                    {
                        return ResponseFail.NoContent();
                    }

                    context.TeamWithUsers.Remove(teamWithUser);

                    context.SaveChanges();
                }   catch (Exception e)
                {
                    return ResponseFail.ExpectationFailed(message: e.Message);
                }

                return ResponseSuccess.Json();
            }));
        }
示例#2
0
        /// <summary>
        /// Delete user by user id.
        /// </summary>
        /// <param name="userId">User's id.</param>
        /// <returns></returns>
        public Task <string> DeleteUser(int userId)
        {
            return(Task.Run(() =>
            {
                var user = context.Users.ToList().Find(t => t.Id == userId);
                if (user == null)
                {
                    return ResponseFail.Json("", "无此用户,操作失败", 204);
                }

                context.Users.Remove(user);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    return ResponseFail.Json("", e.Message);
                }

                return ResponseSuccess.Json();
            }));
        }
示例#3
0
        /// <summary>
        /// User login.
        /// </summary>
        /// <param name="dto">Login information.</param>
        /// <returns></returns>
        public Task <string> Login(LoginDTO login)
        {
            return(Task.Run(() =>
            {
                if (login == null)
                {
                    return ResponseFail.Json("", "用户名和密码为空");
                }
                else if (!string.IsNullOrEmpty(login.AuthToken))
                {
                    LoginUserInfo userInfo = UserLoginCache.FindUser(login.AuthToken);
                    if (userInfo.ID == 0)
                    {
                        return ResponseFail.Json("[AuthToken]无效");
                    }

                    if (!userInfo.OutTime())
                    {
                        return ResponseSuccess.Json(UserLoginCache.FindUser(login.AuthToken));
                    }
                }
                else if (string.IsNullOrEmpty(login.UserName))
                {
                    return ResponseFail.Json("", "用户名为空");
                }
                else if (string.IsNullOrEmpty(login.Password))
                {
                    return ResponseFail.Json("", "密码为空");
                }
                else if (string.IsNullOrEmpty(login.TimeStamp))
                {
                    return ResponseFail.Json("", "参数异常,请检查[TimeStamp]");
                }
                else if (!Utils.CompareMD5(login.Token, string.Format("{0}-{1}", login.UserName, login.TimeStamp)))
                {
                    return ResponseFail.Json("", "参数异常,请检查[Token]");
                }

                User user = context.Users.ToList().Find(t => t.UserName == login.UserName);
                if (user == null)
                {
                    return CheckLoginInfo();
                }
                else if (string.IsNullOrEmpty(user.Password))
                {
                    return ResponseFail.Json("", "未设置密码");
                }
                else
                {
                    if (user.Password == login.Password)
                    {
                        string token = Utils.MD5(string.Format("{0}-{1}-{2}", user.UserName, login.TimeStamp, DateTime.Now.ToUniversalTime().ToString()));
                        UserLoginCache.AddUserCache(token, user);
                        return ResponseSuccess.Json(UserLoginCache.FindUser(token));
                    }
                    else
                    {
                        return CheckLoginInfo();
                    }
                }
            }));
        }