Пример #1
0
        //public dynamic Postusers(dynamic data)
        public dynamic resetPassword(FormUsersResetPassword data)
        {
            List <string> errList = new List <string>();

            if (!db.users.Any(o => o.userID == data.userID))
            {
                errList.Add("userNotExistErr");
                return(JsonTool.toJson(errList));
            }

            var user = (from p in db.users
                        where p.userID == data.userID
                        select p).SingleOrDefault();
            int status = (int)user.status;

            if (status == -1)
            {
                errList.Add("userBannedErr");
                return(JsonTool.toJson(errList));
            }
            if (status == 0)
            {
                errList.Add("userNotActivateErr");
                return(JsonTool.toJson(errList));
            }

            foreach (ModelState modelState in ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    errList.Add(error.ErrorMessage.ToString());
                }
            }

            if (errList.Count > 0)
            {
                return(JsonTool.toJson(errList));
            }

            user.password = HashTool.getHash(data.password);
            UsersCmd.changePassword(user);
            return(JsonTool.toJson(user));
        }
Пример #2
0
        public dynamic Get(int userID, string hashed)
        {
            if (!HashTool.VerifyMd5Hash(userID.ToString(), hashed))
            {
                var err = new { err = "verify url format invalid" };
                return(JsonTool.toJson(err));
            }

            var user =
                (from p in db.users
                 where p.userID.Equals(userID)
                 select p).SingleOrDefault();

            int status = (int)user.status;

            String baseURL  = Request.RequestUri.GetLeftPart(UriPartial.Authority);
            String url      = baseURL + "/front/showMsg.html";
            String msgToken = "";
            String htmlStr  = "";

            if (status.Equals(-1))
            {
                msgToken = "userBanned";
            }
            if (status.Equals(0))
            {
                UsersCmd.changeStatus(user, 1);
                msgToken = "userActivated";
            }
            if (status.Equals(1))
            {
                msgToken = "userAlreadyActivated";
            }

            htmlStr =
                @"
<!DOCTYPE html>
<html lang='en'>
<head>
<title>plz w8</title>
<meta charset = 'utf-8'>
<meta name = 'viewport' content = 'width=device-width, initial-scale=1'>
<link rel = 'stylesheet' href = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script src = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
</head>
<body>
<div class='container'>
</div>
<script>
"
                + "sessionStorage.setItem('msgToken'," + "'" + msgToken + "'" + ");"
                + "sessionStorage.setItem('userNickname'," + "'" + user.nickname + "'" + ");"
                + "sessionStorage.setItem('userEmail'," + "'" + user.email + "'" + ");"
                + "window.location='" + url + "';"

                + @"
</script>
</body>
</html>";

            var response = new HttpResponseMessage();

            response.Content = new StringContent(htmlStr);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
Пример #3
0
        public dynamic userRegister(FormUsersRegister data)
        {
            List <string> errList = new List <string>();

            foreach (ModelState modelState in ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    errList.Add(error.ErrorMessage.ToString());
                }
            }

            if (db.users.Any(o => o.email == data.email))
            {
                errList.Add("emailExistErr");
            }

            if (db.users.Any(o => o.nickname == data.nickname))
            {
                errList.Add("nicknameExistErr");
            }

            if (errList.Count > 0)
            {
                return(JsonTool.toJson(errList));
            }

            users newOne = new users
            {
                email     = data.email,
                nickname  = data.nickname,
                password  = HashTool.getHash(data.password),
                gender    = data.gender,
                birthDate = DateTime.ParseExact(data.birthDate.Replace("-", "/"), "yyyy/MM/dd", CultureInfo.InvariantCulture),
                createAt  = DateTime.Now,
                updateAt  = DateTime.Now
            };

            if (UsersCmd.insert(newOne) <= 0)
            {
                errList.Add("dbInsertErr");
                return(JsonTool.toJson(errList));
            }
            ;

            newOne.userID = (from p in db.users
                             where p.email == data.email
                             select p).SingleOrDefault().userID;


            //send verify email
            string baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);

            UsersEmail.sendValidateEmail(newOne, baseUrl);

            var obj =
                (
                    from p in db.users
                    where p.userID == newOne.userID
                    select new
            {
                p.userID,
                p.email,
                p.nickname,
                p.gender,
                p.birthDate,
                p.createAt
            }
                ).SingleOrDefault();

            return(JsonTool.toJson(obj));
        }