Exemplo n.º 1
0
        public ActionResult <ResponseModel> PostRegister([FromBody] RequestModel req)
        {
            var user = new UserModel
            {
                uuid     = UUIDModel.GetUUID(),
                name     = (string)req.data["name"],
                password = (string)req.data["password"],
                datetime = DateTime.Now
            };

            _context.User.Add(user);
            _context.SaveChanges();

            return(new ResponseModel
            {
                status = 200,
                statusText = "success"
            });
        }
Exemplo n.º 2
0
        public ActionResult <ResponseModel> PostSignIn([FromBody] RequestModel req)
        {
            var user  = new UserModel();
            var data  = new Newtonsoft.Json.Linq.JObject();
            var token = new Newtonsoft.Json.Linq.JObject();
            var auth  = new AuthModel();
            var _auth = new AuthModel();

            try
            {
                user          = _context.User.Single(u => u.name == (string)req.data["name"] && u.password == (string)req.data["password"]);
                auth.uuid     = user.uuid;
                auth.token    = UUIDModel.GetUUID("N") + UUIDModel.GetUUID("N");
                auth.datetime = DateTime.Now;
                _context.Auth.Add(auth);
                _context.SaveChanges();

                _auth = _context.Auth.Single(a => a.token == auth.token);
            }
            catch (Exception ex)
            {
                data["msg"] = ex.Message;
                return(new ResponseModel
                {
                    status = 404,
                    statusText = "failure",
                    data = data
                });
            }
            data["uuid"]   = user.uuid;
            data["name"]   = user.name;
            token["id"]    = _auth.id;
            token["token"] = _auth.token;
            data["token"]  = token;
            HttpContext.Session.SetString("token", _auth.token);
            return(new ResponseModel
            {
                status = 200,
                statusText = "success",
                data = data
            });
        }
Exemplo n.º 3
0
        public ActionResult <ResponseModel> PostInsert([FromBody] UserModel _user)
        {
            _user.uuid     = UUIDModel.GetUUID();
            _user.datetime = DateTime.Now;
            _context.User.Add(_user);
            _context.SaveChanges();
            return(new ResponseModel
            {
                status = 200,
                statusText = "success",

                /*
                 * data = new UserModel
                 * {
                 *  id = _user.id,
                 *  uuid = _user.uuid,
                 *  name = _user.name,
                 * }
                 */
            });
        }