public IHttpActionResult SendLoginOtp(Login model) { Otp otpModel = new Otp(); otpModel.MobileOtp = sendOtp.GenerateOtp(); try { string otpQuery = string.Empty; if (model.DocType != "individual") { otpQuery = @"SELECT meta().id as Id,email,mobNum,emirateId From " + _bucket.Name + " as APTCCRM where meta().id like 'login_%' and email='" + model.Email + "' and `password`='" + EncryptDecryptString.EncodePasswordToBase64(model.Password) + "' and docType='user'"; } else { otpQuery = @"SELECT meta().id as Id,email,mobNum,emirateId From " + _bucket.Name + " as APTCCRM where meta().id like 'login_%' and email='" + model.Email + "' and `password`='" + EncryptDecryptString.EncodePasswordToBase64(model.Password) + "' and docType='individual'"; } var userDocument = _bucket.Query <object>(otpQuery).ToList(); if (userDocument.Count > 0) { string mobileNo = ""; string emirateId = ""; foreach (var item in userDocument) { mobileNo = ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"].ToString(); otpModel.Email = ((Newtonsoft.Json.Linq.JToken)item).Root["email"].ToString(); if (((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["countryCodeM"].ToString().Contains("+")) { otpModel.MobileNo = ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["countryCodeM"].ToString() + ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["areaM"].ToString() + ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["numM"].ToString(); } else { otpModel.MobileNo = "+" + ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["countryCodeM"].ToString() + ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["areaM"].ToString() + ((Newtonsoft.Json.Linq.JToken)item).Root["mobNum"]["numM"].ToString(); } otpModel.MobileOtp = otpModel.MobileOtp; } if (string.IsNullOrEmpty(emirateId)) { } //JObject jsonObj = JObject.Parse(userDocument[0].ToString()); //JObject jsonmobNumObj = JObject.Parse(jsonObj["APTCCRM"]["mobNum"].ToString()); //string area = (string)jsonmobNumObj["areaM"].ToString(); //if (string.IsNullOrEmpty("area")) //{ // area = string.Empty; //} //string mobileNo = (string)jsonmobNumObj["countryCodeM"] + area + (string)jsonmobNumObj["numM"]; //otpModel.KeyId = (string)jsonObj["APTCCRM"]["keyID"]; //otpModel.MobileNo = mobileNo; //otpModel.MobileOtp = otpModel.MobileOtp; var sendResult = mobileSMS.SendOtpViaMobile(otpModel.MobileNo, otpModel.MobileOtp, otpModel.Email); if (sendResult == "200") { return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, otpModel.Email), new JsonMediaTypeFormatter())); } else { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), sendResult), new JsonMediaTypeFormatter())); } } else { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "179-invalid userid or password"), new JsonMediaTypeFormatter())); } } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } }
public async Task <IHttpActionResult> InsertUser(Login model) { //string ppp = EncryptDecryptString.DecodePasswordToFrom64("MTIzNDU2OTk5"); try { if (string.IsNullOrEmpty(model.Name)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "224-name is required"), new JsonMediaTypeFormatter())); } if (string.IsNullOrEmpty(model.Email)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "112-email is required"), new JsonMediaTypeFormatter())); } if (string.IsNullOrEmpty(model.Password)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "158-Password is required"), new JsonMediaTypeFormatter())); } var userDocumentEmail = _bucket.Query <object>(@"SELECT * From " + _bucket.Name + " where email= '" + model.Email + "' and isActive=true and isActive=true and meta().id like'%login_%'").ToList(); if (userDocumentEmail.Count > 0) { return(Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "105-The e-mail already exists"), new JsonMediaTypeFormatter())); } if (model.MobNum == null) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "199-mobnum is required"), new JsonMediaTypeFormatter())); } else { if (string.IsNullOrEmpty(model.MobNum.AreaM)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "200-areaM is required"), new JsonMediaTypeFormatter())); } if (string.IsNullOrEmpty(model.MobNum.NumM)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "201-NumM is required"), new JsonMediaTypeFormatter())); } if (string.IsNullOrEmpty(model.MobNum.CountryCodeM)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "202-CountryCodeM is required"), new JsonMediaTypeFormatter())); } } if (model.Roles == null) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "203-roles is required"), new JsonMediaTypeFormatter())); } else { if (string.IsNullOrEmpty(model.Roles.PrimaryRole)) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "204-PrimaryRole is required"), new JsonMediaTypeFormatter())); } if (model.Roles.OtherRoles == null) { return(Content(HttpStatusCode.BadRequest, MessageResponse.Message(HttpStatusCode.BadRequest.ToString(), "205-OtherRoles is required"), new JsonMediaTypeFormatter())); } } var userDocumentPhone = _bucket.Query <object>(@"SELECT * From " + _bucket.Name + " where " + _bucket.Name + ".mobNum.num= '" + model.MobNum.NumM + "' and isActive=true and meta().id like'%login_%'").ToList(); if (userDocumentPhone.Count > 0) { return(Content(HttpStatusCode.Conflict, MessageResponse.Message(HttpStatusCode.Conflict.ToString(), "Mobile number already exists"), new JsonMediaTypeFormatter())); } try { List <PrevPassword> prevPassword = new List <PrevPassword>(); var loginDocumentId = "login_" + Guid.NewGuid(); MobNum mobNum = new MobNum(); mobNum.CountryCodeM = model.MobNum.CountryCodeM; mobNum.NumM = model.MobNum.NumM; mobNum.AreaM = model.MobNum.AreaM; TelNum telNum = new TelNum(); if (model.TelNum != null) { telNum.CountryCodeT = model.TelNum.CountryCodeT; telNum.NumT = model.TelNum.NumT; telNum.AreaT = model.TelNum.AreaT; } var loginDocument = new Document <Login>() { Id = loginDocumentId, Content = new Login { Lang = model.Lang, DocType = "user", Name = model.Name, PassSetDate = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()), Password = EncryptDecryptString.EncodePasswordToBase64(model.Password), Email = model.Email, EmirateId = model.EmirateId, //Mobile = model.Mobile, MobNum = mobNum, TelNum = telNum, Department = model.Department, Roles = model.Roles, PrevPass = prevPassword, IsActive = true, Created_By = model.Email, UserPhoto = model.UserPhoto, Created_On = DataConversion.ConvertYMDHMS(DateTime.Now.ToString()), }, }; var result = _bucket.Insert(loginDocument); if (!result.Success) { //_bucket.Remove(loginResult.Document.Content.Email); return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), result.Message), new JsonMediaTypeFormatter())); } return(Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result.Document.Content.Email), new JsonMediaTypeFormatter())); } catch (Exception ex) { //_bucket.Remove(result.Document.Id); return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.Message), new JsonMediaTypeFormatter())); } //} // return Content(HttpStatusCode.OK, MessageResponse.Message(HttpStatusCode.OK.ToString(), MessageDescriptions.Add, result..Id), new JsonMediaTypeFormatter()); //} } catch (Exception ex) { return(Content(HttpStatusCode.InternalServerError, MessageResponse.Message(HttpStatusCode.InternalServerError.ToString(), ex.StackTrace), new JsonMediaTypeFormatter())); } }