// POST: api/ResetPassword public async Task <object> Post(HttpRequestMessage requestMessage, [FromBody] JObject request) { var messageId = requestMessage.GetCorrelationId().ToString(); TraceSources.AddAdditionalLogItem("RequestMessageId", messageId); var emailAddress = ""; try { var personReq = GetRequestJsosn_PersonForRemindPass(request.ToString()); var companyReq = GetRequestJson_CompanyForRemindPass(request.ToString()); var person = personReq.person; var company = companyReq.company; if (person != null) { if (person.member_id == null || person.birthday == null || person.email == null) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "必須要素が存在しない", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } var memberId = person.member_id; var strBirth = person.birthday; emailAddress = person.email; if (memberId.Equals(string.Empty) || memberId.Length > 256) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "会員ID", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } //入力チェック if (emailAddress.Equals(string.Empty) || emailAddress.Length > 256) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "メールアドレス", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } try { DateTime.ParseExact(strBirth, "yyyyMMdd", null); } catch (Exception) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "誕生日", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } //個人の場合I003000213 会員ログイン情報取得を呼びだす var reminder = new Toyota.Gbook.WebSite.Authentication.Control.Reminder(); //パスワード変更の場合はT-ConnectIdを指定しているため取得できうる内部会員IDは常に1件のみ。 var memberInfoList = reminder.CheckPersonalMemberExist(memberId, strBirth, emailAddress)[0]; var token = StoreVerificationData(emailAddress, memberInfoList.InternalMemberId, ReminderConstants.IsPersonalMember); await MailSend(new MailAddress(emailAddress), token); return(requestMessage.CreateResponse(HttpStatusCode.Accepted, new SuccessResponse_MessageId { message_id = messageId })); } else if (company != null) { if (company.member_id == null || company.frame_no == null || company.email == null) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "必須要素が存在しない", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } var memberId = company.member_id; emailAddress = company.email; var vin = company.frame_no; if (memberId.Equals(string.Empty) || memberId.Length > 256) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "会員ID", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } if (emailAddress.Equals(string.Empty) || emailAddress.Length > 256) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "メールアドレス", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } if (vin.Equals(string.Empty) || vin.Length > 20) { PCSiteTraceSource.InvalidRequest_Api("api/reset-password", "VIN", null); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } //法人の場合00901:テレマサービス汎用操作API.テレマサービス契約情報取得を呼びだす var reminder = new Toyota.Gbook.WebSite.Authentication.Control.Reminder(); var memberInfo = reminder.CheckCompanyMemberExist(memberId, emailAddress, vin); var token = StoreVerificationData(emailAddress, memberInfo.InternalMemberId, ReminderConstants.IsCompanyMember); await MailSend(new MailAddress(emailAddress), token); return(requestMessage.CreateResponse(HttpStatusCode.Accepted, new SuccessResponse_MessageId { message_id = messageId })); } return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } catch (InvalidJsonException) { return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } catch (UserNotFoundException) { var encoding = Encoding.GetEncoding("UTF-8"); var emailBytes = encoding.GetBytes(emailAddress); var emailBase64 = System.Convert.ToBase64String(emailBytes); var ex = PCSiteTraceSource.UserNotFound_Api(emailBase64); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.Unauthorized, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (UnexpectedMemberDivisionException) { var encoding = Encoding.GetEncoding("UTF-8"); var emailBytes = encoding.GetBytes(emailAddress); var emailBase64 = System.Convert.ToBase64String(emailBytes); var ex = PCSiteTraceSource.UnexpectedMemberDivision_Api(emailBase64); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.Unauthorized, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (MissingFileOnBlobException mex) { var ex = PCSiteTraceSource.FileMissingOnBlob_Api(mex.FileName, mex); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (UnexpectedResultCodeException uex) { var ex = PCSiteTraceSource.UnexpectedResultCode_Api(uex.api, uex.resultCode); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (GetMemberLoginInfoFailException gex) { var ex = PCSiteTraceSource.NetworkAccessFail_Api("00000_common/Member.svc/rest/GetMemberLoginInformation", gex); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (TelemaServiceGeneralOperationFailException tex) { var ex = PCSiteTraceSource.NetworkAccessFail_Api("00000_common/TelemaServiceGeneralOperation.sv/rest/GetTelemaServiceContract", tex); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (WebApplicationFatalException wex) { var ex = PCSiteTraceSource.MethodFailure(string.Format("パスワードリセットAPIでエラーが発生。URL{0}, レスポンス:{1}", wex.Url, wex.Response)); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } catch (Exception e) { var ex = PCSiteTraceSource.SystemError_Api("パスワードリセットAPIで想定外のエラーが発生", e); var id = 0; ex.TryGetId(out id); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", id.ToString() } } })); } }
public async Task <object> Post(HttpRequestMessage requestMessage, [FromBody] JObject request) { var messageId = requestMessage.GetCorrelationId().ToString(); TraceSources.AddAdditionalLogItem("RequestMessageId", messageId); try { CheckRequest(request); var requestXml = JsonConvert.DeserializeXmlNode(request.ToString(), "contact"); var xmlDeclaration = requestXml.CreateXmlDeclaration("1.0", "UTF-8", null); using (var stringwriter = new StringWriter()) using (var xmltextWriter = new XmlTextWriter(stringwriter)) { xmlDeclaration.WriteTo(xmltextWriter); requestXml.WriteTo(xmltextWriter); var requestBodyXml = stringwriter.ToString(); var url = new Uri(Config.Get <string>("Toyota.Gbook.WebSite.Contact.MemberUtilityApi.Url")); using (var client = new HttpClient()) using (var m = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = url, Content = new StringContent(requestBodyXml) }) { m.Headers.Add("MessageId", messageId); var xid = Config.Get <string>("Toyota.Gbook.WebSite.TConnect.XId"); var xpass = Config.Get <string>("Toyota.Gbook.WebSite.TConnect.XPassword"); m.Headers.Add("X-ID", xid); m.Headers.Add("X-Password", xpass); PCSiteTraceSource.ApiExecute_Api("問合せAPI(オンプレ)", url.ToString(), requestBodyXml); var response = await client.SendAsync(m); var responseXml = await response.Content.ReadAsStringAsync(); PCSiteTraceSource.ApiResponsed_Api("問合せAPI(オンプレ)", response.StatusCode, responseXml); if (response.StatusCode == HttpStatusCode.OK) { var x = new XmlDocument(); x.LoadXml(responseXml); var code = x.SelectSingleNode("//contact/result_code").InnerText; var result_message = x.SelectSingleNode("//contact/result_code_message").InnerText; if (code == "000000") { if (request["registered"]["user_id"] == null) { return(new SuccessResponse { UserId = "", Datetime = request["inquiry"]["input_date"].ToString() + request["inquiry"]["input_time"] }); } else { return(new SuccessResponse { UserId = request["registered"]["user_id"].ToString(), Datetime = request["inquiry"]["input_date"].ToString() + request["inquiry"]["input_time"] }); } } if (code == "100002") { //入力チェックエラー var trace = PCSiteTraceSource.UnexpectedResultCode_Api(url.ToString(), code); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } if (code == "300000") { //DBアクセスエラー var trace = PCSiteTraceSource.UnexpectedResultCode_Api(url.ToString(), code); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", errorCode.ToString() } } })); } if (code == "500000") { var trace = PCSiteTraceSource.InvalidRequest_Api(url.ToString(), requestBodyXml, null); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", errorCode.ToString() } } })); } if (code == "600000") { var trace = PCSiteTraceSource.ValueMissing_Api(url.ToString(), "処理結果コード"); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", errorCode.ToString() } } })); } if (code == "900000") { var trace = PCSiteTraceSource.SystemError_Api(string.Format("問合せAPI(オンプレ)で想定外のエラーが発生。メッセージ:", result_message), null); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", errorCode.ToString() } } })); } var errorTrace = PCSiteTraceSource.UnexpectedResultCode(url.ToString(), code); var unexpcetErrorCode = 0; errorTrace.TryGetId(out unexpcetErrorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", unexpcetErrorCode.ToString() } } })); } else { var trace = PCSiteTraceSource.UnexpectedHttpStatus_Api(url.ToString(), response.StatusCode, ""); var errorCode = 0; trace.TryGetId(out errorCode); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", errorCode.ToString() } } })); } } } } catch (InvalidRequestForContactException ie) { PCSiteTraceSource.InvalidRequest_Api("tcmypage/api/contact", request.ToString(), ie); return(requestMessage.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception e) { var trace = PCSiteTraceSource.SystemError_Api("問合せAPIで想定外のエラーが発生", e); var code = 0; trace.TryGetId(out code); return(requestMessage.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Errors = new Dictionary <string, string> { { "code", code.ToString() } } })); } }