Example #1
0
        public ActionResult AddRoadBike(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();
            //AppendLog("[REQ HKSports/LoginController]" + json);

            string   actionName = "AddRoadBike";
            DateTime dtNow      = DateTime.Now;

            // 객체 초기화
            JsonRoadBike jsonRoadBike   = null;
            UserInfo     returnUserInfo = new UserInfo();
            HKRheader    rHeader        = new HKRheader();
            UserInfoBody uiBody         = new UserInfoBody();

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                jsonRoadBike = JsonConvert.DeserializeObject <JsonRoadBike>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = jsonRoadBike.header.action;
                newLog.auth_token = jsonRoadBike.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = dtNow;
                newLog.user_id    = jsonRoadBike.body.nickname;
                // Log 처리 루틴 -------------------------------------------------

                if (!jsonRoadBike.header.action.Equals(actionName))
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + jsonRoadBike.header.action,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else if (jsonRoadBike.header.auth_token == null || jsonRoadBike.header.auth_token == "")
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 103, "[ERROR] Auth Token is wrong: " + jsonRoadBike.header.auth_token,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                // User 가져오기
                USER thisUser = (from u in db.USERs
                                 where   u.Auth_Token == jsonRoadBike.header.auth_token
                                 select u).SingleOrDefault();

                if (thisUser == null)
                {
                    //Error 202: 다시 접속하세요. 유저정보를 확인할 수 없습니다.
                    returnUserInfo.header = setHKRheader_Err(rHeader, 202, "[ERROR] 다시 접속하세요. 유저정보를 확인할 수 없습니다: " +
                                                             jsonRoadBike.header.auth_token, jsonRoadBike.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    ROADBIKE theBike = thisUser.ROADBIKEs.Where(r => r.Nickname == jsonRoadBike.body.nickname).SingleOrDefault();

                    if (theBike == null) //신규 바이크.
                    {
                        foreach (ROADBIKE rb in thisUser.ROADBIKEs)
                        {
                            if (rb.DeviceID.Equals(jsonRoadBike.body.device_id))
                            {
                                //Error 204: 이미 존재하는 디바이스 ID입니다.
                                returnUserInfo.header = setHKRheader_Err(rHeader, 204,
                                                                         "[ERROR] 이미 존재하는 디바이스 ID입니다: " + jsonRoadBike.body.device_id + "," +
                                                                         thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                            }
                        }
                        ROADBIKE newRoadBike = new ROADBIKE();
                        newRoadBike.Nickname            = jsonRoadBike.body.nickname;
                        newRoadBike.Type                = (byte)jsonRoadBike.body.type; // 타입을 정수로 보관할 필요가 있는지?
                        newRoadBike.Typename            = jsonRoadBike.body.typename;   // 타입 이름이 있으므로...
                        newRoadBike.WheelSize           = jsonRoadBike.body.wheel_size;
                        newRoadBike.Modelname           = jsonRoadBike.body.modelname;
                        newRoadBike.ColorSize           = jsonRoadBike.body.color_size;
                        newRoadBike.FrameNo             = jsonRoadBike.body.frame_no;
                        newRoadBike.Characteristics     = jsonRoadBike.body.characteristics;
                        newRoadBike.DeviceID            = jsonRoadBike.body.device_id;
                        newRoadBike.Pictures            = jsonRoadBike.body.pictures;
                        newRoadBike.AvatarLevel         = 1;
                        newRoadBike.RidingScore         = 0;
                        newRoadBike.RidingCount         = 0;
                        newRoadBike.DistanceAccumulated = 0;
                        newRoadBike.TimeAccumulated     = 0;
                        newRoadBike.AverageDistance     = 0;
                        newRoadBike.AverageRidingTime   = 0;
                        newRoadBike.CaloriesAccumulated = 0;
                        newRoadBike.AverageCalories     = 0;
                        newRoadBike.Lost                = "N";
                        newRoadBike.LastGPS             = "";

                        newRoadBike.DT_registered = dtNow;
                        newRoadBike.DT_lastaccess = dtNow;
                        //theBike.USERS_id = thisUser.id; // 오류남.

                        thisUser.ROADBIKEs.Add(newRoadBike);
                        thisUser.DT_lastaccess = dtNow;
                    }
                    else // 기존 바이크 업데이트
                    {
                        //theBike.Nickname = jsonRoadBike.body.nickname;
                        theBike.Type            = (byte)jsonRoadBike.body.type; // 타입을 정수로 보관할 필요가 있는지?
                        theBike.Typename        = jsonRoadBike.body.typename;   // 타입 이름이 있으므로...
                        theBike.WheelSize       = jsonRoadBike.body.wheel_size;
                        theBike.Modelname       = jsonRoadBike.body.modelname;
                        theBike.ColorSize       = jsonRoadBike.body.color_size;
                        theBike.FrameNo         = jsonRoadBike.body.frame_no;
                        theBike.Characteristics = jsonRoadBike.body.characteristics;
                        theBike.DeviceID        = jsonRoadBike.body.device_id;
                        theBike.Pictures        = jsonRoadBike.body.pictures;
                        //theBike.Lost = jsonRoadBike.body.lost; // 분실 도움 요청. --> 신고 및 취소에서 만 반영
                        theBike.DT_lastaccess = dtNow;
                        theBike.LastGPS       = jsonRoadBike.body.last_gps;
                    }
                }

                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);

                returnUserInfo.header = rHeader;
                returnUserInfo.body   = uiBody;
                returnUserInfo        = getUserInformation(returnUserInfo, thisUser); // 다시 계정 정보를 받아서 리턴해 준다.

                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                returnUserInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                         , jsonRoadBike == null?"jsonRoadBike is null":jsonRoadBike.header.auth_token, logdb, newLog);
                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public ActionResult AddBikeLost(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();
            //AppendLog("[REQ HKSports/LoginController]" + json);

            string   actionName = "AddBikeLost";
            DateTime dtNow      = DateTime.Now;

            // 객체 초기화
            JsonBikeLost jsonBikeLost   = null;
            UserInfo     returnUserInfo = new UserInfo();
            HKRheader    rHeader        = new HKRheader();
            UserInfoBody uiBody         = new UserInfoBody();

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                jsonBikeLost = JsonConvert.DeserializeObject <JsonBikeLost>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = jsonBikeLost.header.action;
                newLog.auth_token = jsonBikeLost.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = dtNow;
                newLog.user_id    = jsonBikeLost.body.nickname;
                // Log 처리 루틴 -------------------------------------------------

                if (!jsonBikeLost.header.action.Equals(actionName))
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + jsonBikeLost.header.action,
                                                             jsonBikeLost.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else if (jsonBikeLost.header.auth_token == null || jsonBikeLost.header.auth_token == "")
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 103, "[ERROR] Auth Token is wrong: " + jsonBikeLost.header.auth_token,
                                                             jsonBikeLost.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                // User 가져오기
                USER thisUser = (from u in db.USERs
                                 where   u.Auth_Token == jsonBikeLost.header.auth_token
                                 select u).SingleOrDefault();

                if (thisUser == null) // 유저가 존재하는지 확인
                {
                    //Error 202: 다시 접속하세요. 유저정보를 확인할 수 없습니다.
                    returnUserInfo.header = setHKRheader_Err(rHeader, 202, "[ERROR] 다시 접속하세요. 유저정보를 확인할 수 없습니다: " +
                                                             thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else // 분실신고 바이크의 정보가 있는지 확인.
                {
                    ROADBIKE theBike = thisUser.ROADBIKEs.Where(r => r.Nickname == jsonBikeLost.body.nickname).SingleOrDefault();

                    if (theBike == null) //존재하지 않는 바이크.
                    {
                        //Error 205: 아바타 정보를 확인할 수 없습니다. 계속 문제 발생시 다시 로그인해 주세요.
                        returnUserInfo.header = setHKRheader_Err(rHeader, 205, "[ERROR] 아바타 정보를 확인할 수 없습니다. 계속 문제 발생시 다시 로그인해 주세요.: " +
                                                                 thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                        return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                    }
                    else // 분실 신고 테이블에 등록
                    {
                        LOSTBIKE lostBike = (from l in db.LOSTBIKEs
                                             where l.BikeNickname == jsonBikeLost.body.nickname &&
                                             l.DeviceID == jsonBikeLost.body.device_id &&
                                             l.Status.Contains("L")
                                             select l).SingleOrDefault();
                        if (lostBike != null) //이미 분실신고 되어 있음.
                        {
                            //Error 206: 이미 분실신고 되었습니다.
                            returnUserInfo.header = setHKRheader_Err(rHeader, 205, "[ERROR] 이미 분실신고 되었습니다.: " +
                                                                     thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                            return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            LOSTBIKE newLostBike = new LOSTBIKE();
                            newLostBike.BikeNickname = jsonBikeLost.body.nickname;
                            newLostBike.UserName     = jsonBikeLost.body.username;
                            newLostBike.PhoneNo      = jsonBikeLost.body.phone_no;
                            newLostBike.ExtraInfo    = jsonBikeLost.body.extra_info;
                            newLostBike.DeviceID     = jsonBikeLost.body.device_id;
                            newLostBike.LocationLost = jsonBikeLost.body.location_lost;
                            newLostBike.DT_lost      = jsonBikeLost.body.dt_lost;

                            newLostBike.USERS_id        = theBike.USERS_id;
                            newLostBike.ROADBIKES_id    = theBike.id;
                            newLostBike.ModelName       = theBike.Modelname;
                            newLostBike.ColorSize       = theBike.ColorSize;
                            newLostBike.FrameNo         = theBike.FrameNo;
                            newLostBike.Characteristics = theBike.Characteristics;

                            newLostBike.Status        = "L"; // L:losted, F:found, C:canceled
                            newLostBike.DT_registered = dtNow;
                            newLostBike.Dt_updated    = dtNow;

                            db.LOSTBIKEs.InsertOnSubmit(newLostBike); // 분실신고 추가.

                            theBike.Lost          = "Y";              //N: 분실아님, Y: 분실.
                            theBike.DT_lastaccess = dtNow;

                            PUSHRECORD pushRecord = new PUSHRECORD();
                            pushRecord.dt = dtNow;

                            sendFCM_lostbike(newLostBike, "L", pushRecord);

                            db.PUSHRECORDs.InsertOnSubmit(pushRecord);
                        }
                    }
                }


                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);

                returnUserInfo.header = rHeader;
                returnUserInfo.body   = uiBody;
                returnUserInfo        = getUserInformation(returnUserInfo, thisUser); // 다시 계정 정보를 받아서 리턴해 준다.

                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                returnUserInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                         , jsonBikeLost == null?"jsonRoadBike is null": jsonBikeLost.header.auth_token, logdb, newLog);
                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #3
0
        public ActionResult AddRidingLog(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();

            string   actionName = "AddRidingLog";
            DateTime dtNow      = DateTime.Now;

            // 객체 초기화
            JsonRidingLog jsonRidingLog  = null;
            UserInfo      returnUserInfo = new UserInfo();
            HKRheader     rHeader        = new HKRheader();
            UserInfoBody  uiBody         = new UserInfoBody();
            RIDINGLOG     ridingLog;

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                jsonRidingLog = JsonConvert.DeserializeObject <JsonRidingLog>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = jsonRidingLog.header.action;
                newLog.auth_token = jsonRidingLog.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = dtNow;
                // Log 처리 루틴 -------------------------------------------------

                if (!jsonRidingLog.header.action.Equals(actionName))
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + jsonRidingLog.header.action,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else if (jsonRidingLog.header.auth_token == null || jsonRidingLog.header.auth_token == "")
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 103, "[ERROR] Auth Token is wrong: " + jsonRidingLog.header.auth_token,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                // User 가져오기
                USER thisUser = (from u in db.USERs
                                 where   u.Auth_Token == jsonRidingLog.header.auth_token
                                 select u).SingleOrDefault();

                if (thisUser == null)
                {
                    //Error 202: 다시 접속하세요. 유저정보를 확인할 수 없습니다.
                    returnUserInfo.header = setHKRheader_Err(rHeader, 202, "[ERROR] 다시 접속하세요. 유저정보를 확인할 수 없습니다: " +
                                                             jsonRidingLog.header.auth_token, returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    ROADBIKE theBike = thisUser.ROADBIKEs.Where(r => r.DeviceID == jsonRidingLog.body.mac_address).SingleOrDefault();

                    if (theBike == null) //해당 맥주소가 해당 유저에게는 존재하지 않음.
                    {
                        //Error 203: 주행기록을 저장한 유저정보를 확인할 수 없습니다. 다시 접속하세요.
                        returnUserInfo.header = setHKRheader_Err(rHeader, 203, "[ERROR] 주행기록을 저장한 유저정보를 확인할 수 없습니다. 다시 접속하세요.: " +
                                                                 thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                        return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                    }
                    else // 존재함.
                    {
                        ridingLog               = new RIDINGLOG();
                        ridingLog.RidingScore   = (int)jsonRidingLog.body.riding_score;
                        ridingLog.Distance      = (int)jsonRidingLog.body.distance;
                        ridingLog.Duration      = (long)jsonRidingLog.body.duration;
                        ridingLog.DT_Start      = FromMillisJava((long)jsonRidingLog.body.dt_start).ToLocalTime();
                        ridingLog.DT_End        = FromMillisJava((long)jsonRidingLog.body.dt_end).ToLocalTime();
                        ridingLog.AverageSpeed  = (int)jsonRidingLog.body.average_speed;
                        ridingLog.MaxSpeed      = (int)jsonRidingLog.body.max_speed;
                        ridingLog.CaloriesBurn  = (int)jsonRidingLog.body.calories_burn;
                        ridingLog.StartLocation = jsonRidingLog.body.start_location;
                        ridingLog.EndLocation   = jsonRidingLog.body.end_location;
                        ridingLog.GPSrecords    = jsonRidingLog.body.gps_records;
                        ridingLog.LastGPS       = jsonRidingLog.body.last_gps;
                        if (jsonRidingLog.body.debug_data != null)
                        {
                            ridingLog.DebugData = jsonRidingLog.body.debug_data;
                        }
                        ridingLog.dt_registered = dtNow;
                        ridingLog.ROADBIKES_id  = theBike.id;
                        ridingLog.USERS_id      = thisUser.id;

                        int ridingCnt     = theBike.RidingCount + 1;
                        int totalCals     = theBike.CaloriesAccumulated + (int)jsonRidingLog.body.calories_burn;
                        int totalDistance = theBike.DistanceAccumulated + (int)jsonRidingLog.body.distance;
                        int totalRidingT  = theBike.TimeAccumulated + (int)jsonRidingLog.body.duration;

                        int score4max = 0;
                        if (theBike.MaxSpeed < (int)jsonRidingLog.body.max_speed)
                        {
                            theBike.MaxSpeed = (int)jsonRidingLog.body.max_speed;
                            score4max        = (int)(((int)jsonRidingLog.body.max_speed / 3.6) - (theBike.MaxSpeed / 3.6));
                        }
                        int ridingScore = theBike.RidingScore + (int)jsonRidingLog.body.riding_score + score4max;

                        theBike.RidingScore         = ridingScore;
                        theBike.AvatarLevel         = GetLevel(ridingScore);
                        theBike.RidingCount         = ridingCnt;
                        theBike.CaloriesAccumulated = totalCals;
                        theBike.AverageCalories     = totalCals / ridingCnt;
                        theBike.DistanceAccumulated = totalDistance;
                        theBike.AverageDistance     = totalDistance / ridingCnt;
                        theBike.AverageRidingTime   = totalRidingT / ridingCnt;
                        theBike.AverageSpeed        = totalDistance / totalRidingT; //m per sec
                        theBike.TimeAccumulated     = totalRidingT;
                        theBike.LastGPS             = jsonRidingLog.body.last_gps;
                        theBike.RIDINGLOGs.Add(ridingLog);
                        theBike.DT_lastaccess  = dtNow;
                        thisUser.DT_lastaccess = dtNow;
                    }
                }

                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);

                rHeader.ret_string    = ridingLog.id.ToString();
                returnUserInfo.header = rHeader;
                returnUserInfo.body   = uiBody;
                returnUserInfo        = getUserInformation(returnUserInfo, thisUser); // 다시 계정 정보를 받아서 리턴해 준다.

                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                returnUserInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                         , jsonRidingLog == null?"jsonRidingLog is null":jsonRidingLog.header.auth_token, logdb, newLog);
                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #4
0
        public ActionResult GetUserInfo(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();
            //AppendLog("[REQ HKSports/LoginController]" + json);

            DateTime today = DateTime.Now;

            // 객체 초기화
            Login        login    = null;
            UserInfo     userInfo = new UserInfo();
            HKRheader    rHeader  = new HKRheader();
            UserInfoBody uiBody   = new UserInfoBody();

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                login = JsonConvert.DeserializeObject <Login>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = login.header.action;
                newLog.auth_token = login.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = DateTime.Now;
                // Log 처리 루틴 -------------------------------------------------

                if (!login.header.action.Equals("GetUserInfo"))
                {
                    userInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + login.header.action,
                                                       login.header.auth_token, logdb, newLog);
                    return(Json(userInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                if (login.header.client_market == null || login.body.email == null)
                {
                    userInfo.header = setHKRheader_Err(rHeader, 102, "[ERROR] No client_market or No user_id",
                                                       login.header.auth_token, logdb, newLog);
                    return(Json(userInfo, JsonRequestBehavior.AllowGet));
                }

                USER   thisUser = null;
                string passwd   = login.body.password;
                string token    = login.header.auth_token;

                // User 가져오기
                if (passwd != null && passwd.Length > 0)
                {
                    thisUser = (from u in db.USERs
                                where u.EMail == login.body.email &&
                                u.Client_Market == login.header.client_market &&
                                u.Passwd == passwd
                                select u).SingleOrDefault();
                }
                else if (token != null && token.Length > 0)
                {
                    thisUser = (from u in db.USERs
                                where u.EMail == login.body.email &&
                                u.Client_Market == login.header.client_market &&
                                u.Auth_Token == token
                                select u).SingleOrDefault();
                }

                if (thisUser == null)
                {
                    // Error: 아이디, 패스워드를 다시 확인하세요.
                    userInfo.header = setHKRheader_Err(rHeader, 201, "[ERROR] 아이디, 패스워드를 다시 확인하세요: " +
                                                       login.body.email, login.header.auth_token, logdb, newLog);
                    return(Json(userInfo, JsonRequestBehavior.AllowGet));
                }

                // 토큰 발급: 로그인으로 들어온 경우는 대부분 Expired 된 경우이다.
                if (token != null && token.Length > 0 && !token.Equals(thisUser.Auth_Token) ||
                    thisUser.Auth_Token == null || thisUser.Auth_Token == "")
                {
                    token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                    thisUser.Auth_Token = token;
                }

                if (!login.header.auth_device_id.Equals(thisUser.FCM_Token))
                {
                    thisUser.FCM_Token = login.header.auth_device_id;
                }


                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);
                logdb.SubmitChanges();

                userInfo.header = rHeader;
                userInfo.body   = uiBody;
                userInfo        = getUserInformation(userInfo, thisUser);

                //userInfo.header = rHeader;
                //userInfo.body = uiBody;
                return(Json(userInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                userInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                   , login == null ? "Login is null" : login.header.auth_token, logdb, newLog);
                return(Json(userInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #5
0
        public ActionResult ReportBikeLost(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();
            //AppendLog("[REQ HKSports/LoginController]" + json);

            string   actionName = "ReportBikeLost";
            DateTime dtNow      = DateTime.Now;

            // 객체 초기화
            JsonBikeLost jsonBikeLost   = null;
            UserInfo     returnUserInfo = new UserInfo();
            HKRheader    rHeader        = new HKRheader();
            UserInfoBody uiBody         = new UserInfoBody();

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                jsonBikeLost = JsonConvert.DeserializeObject <JsonBikeLost>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = jsonBikeLost.header.action;
                newLog.auth_token = jsonBikeLost.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = dtNow;
                newLog.user_id    = jsonBikeLost.body.nickname;
                // Log 처리 루틴 -------------------------------------------------

                if (!jsonBikeLost.header.action.Equals(actionName))
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + jsonBikeLost.header.action,
                                                             jsonBikeLost.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else if (jsonBikeLost.header.auth_token == null || jsonBikeLost.header.auth_token == "")
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 103, "[ERROR] Auth Token is wrong: " + jsonBikeLost.header.auth_token,
                                                             jsonBikeLost.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                // User 가져오기
                USER thisUser = (from u in db.USERs
                                 where   u.Auth_Token == jsonBikeLost.header.auth_token
                                 select u).SingleOrDefault();

                if (thisUser == null) // 유저가 존재하는지 확인
                {
                    //Error 202: 다시 접속하세요. 유저정보를 확인할 수 없습니다.
                    returnUserInfo.header = setHKRheader_Err(rHeader, 202, "[ERROR] 다시 접속하세요. 유저정보를 확인할 수 없습니다: " +
                                                             thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else // 분실신고 바이크의 정보가 있는지 확인.
                {
                    ROADBIKE theBike = db.ROADBIKEs.Where(r => r.Nickname == jsonBikeLost.body.nickname).SingleOrDefault();

                    if (theBike == null) //존재하지 않는 바이크.
                    {
                        //Error 205: 아바타 정보를 확인할 수 없습니다. 계속 문제 발생시 다시 로그인해 주세요.
                        returnUserInfo.header = setHKRheader_Err(rHeader, 205, "[ERROR] 아바타 정보를 확인할 수 없습니다. 계속 문제 발생시 다시 로그인해 주세요.: " +
                                                                 thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                        return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                    }
                    else // 분실 신고 테이블에 등록
                    {
                        USER theUser = db.USERs.Where(u => u.id == theBike.USERS_id).SingleOrDefault();
                        if (theUser == null) // 유저가 존재하는지 확인
                        {
                            //Error 202: 다시 접속하세요. 유저정보를 확인할 수 없습니다.
                            returnUserInfo.header = setHKRheader_Err(rHeader, 202, "[ERROR] 다시 접속하세요. 유저정보를 확인할 수 없습니다: " +
                                                                     theUser.EMail, thisUser.Auth_Token, logdb, newLog);
                            return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                        }

                        LOSTBIKE lostBike = (from l in db.LOSTBIKEs
                                             where l.BikeNickname == jsonBikeLost.body.nickname &&
                                             l.DeviceID == jsonBikeLost.body.device_id &&
                                             l.Status.Contains("L")
                                             select l).SingleOrDefault();
                        if (lostBike == null) //존재하지 않는 분실신고.
                        {
                            //Error 207: 취소할 분실신고가 없습니다.
                            returnUserInfo.header = setHKRheader_Err(rHeader, 207, "[ERROR] 취소할 분실신고가 없습니다.: " +
                                                                     thisUser.EMail, thisUser.Auth_Token, logdb, newLog);
                            return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            theBike.LastGPS = jsonBikeLost.body.dt_lost + ":" + jsonBikeLost.body.location_lost;

                            PUSHRECORD pushRecord = new PUSHRECORD();
                            pushRecord.dt = dtNow;

                            sendFCM_lostbike_found(theUser, jsonBikeLost.body, pushRecord);

                            db.PUSHRECORDs.InsertOnSubmit(pushRecord);
                        }
                    }
                }


                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);

                returnUserInfo.header = rHeader;
                returnUserInfo.body   = uiBody;
                returnUserInfo        = getUserInformation(returnUserInfo, thisUser); // 다시 계정 정보를 받아서 리턴해 준다.

                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                returnUserInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                         , jsonBikeLost == null?"jsonRoadBike is null": jsonBikeLost.header.auth_token, logdb, newLog);
                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #6
0
        public ActionResult RemoveRoadBike(int?id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();
            //AppendLog("[REQ HKSports/LoginController]" + json);

            string   actionName = "RemoveRoadBike";
            DateTime dtNow      = DateTime.Now;

            // 객체 초기화
            JsonRoadBike jsonRoadBike   = null;
            UserInfo     returnUserInfo = new UserInfo();
            HKRheader    rHeader        = new HKRheader();
            UserInfoBody uiBody         = new UserInfoBody();

            LOG newLog = new LOG(); // 로그 객체

            // DB Context 가져오기
            HKRiderDBDataContext db    = new HKRiderDBDataContext(/*connectionString here */);
            LOGDBDataContext     logdb = new LOGDBDataContext(/**/);

            try
            {
                jsonRoadBike = JsonConvert.DeserializeObject <JsonRoadBike>(json);

                // Log 처리 루틴 -------------------------------------------------
                newLog.action     = jsonRoadBike.header.action;
                newLog.auth_token = jsonRoadBike.header.auth_token;
                newLog.json       = json;
                newLog.dt_created = dtNow;
                // Log 처리 루틴 -------------------------------------------------

                if (!jsonRoadBike.header.action.Equals(actionName))
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 101, "[ERROR] Action is wrong: " + jsonRoadBike.header.action,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }
                else if (jsonRoadBike.header.auth_token == null || jsonRoadBike.header.auth_token == "")
                {
                    returnUserInfo.header = setHKRheader_Err(rHeader, 103, "[ERROR] Auth Token is wrong: " + jsonRoadBike.header.auth_token,
                                                             returnUserInfo.header.auth_token, logdb, newLog);
                    return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
                }

                // Version Check 추가 예정

                List <RIDINGLOG> removeList = db.RIDINGLOGs.Where(r => r.ROADBIKES_id == jsonRoadBike.body.id).ToList();
                db.RIDINGLOGs.DeleteAllOnSubmit(removeList);

                var removeObj = db.ROADBIKEs.Where(r => r.id == jsonRoadBike.body.id).SingleOrDefault();
                db.ROADBIKEs.DeleteOnSubmit(removeObj);

                // User 가져오기
                USER thisUser = (from u in db.USERs
                                 where u.Auth_Token == jsonRoadBike.header.auth_token
                                 select u).SingleOrDefault();
                thisUser.DT_lastaccess = dtNow;

                db.SubmitChanges();
                logdb.LOGs.InsertOnSubmit(newLog);

                returnUserInfo.header = rHeader;
                returnUserInfo.body   = uiBody;
                returnUserInfo        = getUserInformation(returnUserInfo, thisUser); // 다시 계정 정보를 받아서 리턴해 준다.

                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                // Error: Exception
                returnUserInfo.header = setHKRheader_Err(rHeader, 301, "[ERROR] Exception: " + ex.Message
                                                         , jsonRoadBike == null?"jsonRoadBike is null":jsonRoadBike.header.auth_token, logdb, newLog);
                return(Json(returnUserInfo, JsonRequestBehavior.AllowGet));
            }
        }