public JsonDocument SetBxUser([FromBody] newBxUser newBxUser) { if (!authUser.is_admin) { return(throwError("თქვენ არ გაქვთ ამ ოპერაციის განხორციელების უფლება")); } if (string.IsNullOrWhiteSpace(newBxUser.refreshToken)) { return(throwError("შეავსეთ შიფრის ველი.")); } if (!string.IsNullOrWhiteSpace(newBxUser.email) && !string.IsNullOrWhiteSpace(newBxUser.password) && !string.IsNullOrWhiteSpace(newBxUser.antsEmail)) { var newBxUserID = 0; var http = new HttpClient(); var responseMessage = http.GetAsync(new BXManager().bxRestUrl + "profile?auth=" + newBxUser.accessToken).Result; if (responseMessage.StatusCode == HttpStatusCode.OK) { var res = responseMessage.Content.ReadAsStringAsync(); newBxUserID = Convert.ToInt32(JsonDocument.Parse(res.Result.ToString()).RootElement.GetProperty("result").GetProperty("ID").ToString()); } if (newBxUserID == 0) { return(throwError("ბიტრიქსის UserID ვერ დადგინდა.")); } var x = new PKG_USERS().setBxUser(newBxUser.email, newBxUser.password, newBxUser.antsEmail, newBxUser.refreshToken, Convert.ToInt32(newBxUserID)); return(Success(x)); } else { return(throwError("შეავსეთ ყველა ველი")); } }
public async Task <JsonDocument> refreshAndCheckNotifications([FromQuery] string key) { if (key == "5cdd1205f9569ef2d78b25f20eec53e7") // md5 from String(http://ants.ge/refreshTokens) { // BXManager bxManager = new BXManager(); // var x = bxManager.AuthBitrix(refreshToken); var users = new PKG_USERS().GetAllBxUsers(); foreach (var user in users) { try { BXManager bxManager = new BXManager(); var jsonToken = bxManager.AuthBitrix(user.bx_refresh_token); string json = null; json = jsonToken.Result.ToString(); if (string.IsNullOrEmpty(json)) { continue; } // if succeed deserialize var obj = new BitrixUserToken(); obj = JsonSerializer.Deserialize <BitrixUserToken>(json); // save if (obj.refresh_token.ToString().Length > 0) { new PKG_USERS().saveBxRefreshToken(obj.refresh_token.ToString(), user.ID); } // if succeed check for chat notifications var bxController = new BitrixController(); BitrixNotifications bxNotifs = new BitrixNotifications(); bxNotifs = await bxController.GetBxNotifications(obj.access_token); if (bxNotifs != null && (Convert.ToInt32(bxNotifs.CHAT) + Convert.ToInt32(bxNotifs.DIALOG)) > 0) { var emailTo = user.email; //emailTo = "*****@*****.**"; new EmailService().SendEmail(emailTo, "წაუკითხავი შეტყობინებები", "<b>თქვენ გაქვთ " + (Convert.ToInt32(bxNotifs.CHAT) + Convert.ToInt32(bxNotifs.DIALOG)) + " წაუკითხავი შეტყობინება.</b> გთხოვთ წაიკითხოთ https://crm.ants.ge/Chat"); } } catch (Exception ex) { // Does not automatically log errors since the program must not stop, it has to continue refreshing bx Refresh tokens. That's why i log manually here // AuthUser.ID = -1 means it's Job Error new PKG_ERROR_LOGS().LogException(-1, ex.Message, ex.StackTrace, "/AutomaticJob/refreshAndCheckNotifications", HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.Request.QueryString.ToString()); } } ; return(Success()); } else { return(throwError("invalid action")); } }
public JsonDocument GetUserModules() { var x = new PKG_USERS().GetUserModules(authUser.ID); if (!authUser.is_emp && x.Count(x => x.empOnly == true) > 0) { x.RemoveAll(x => x.empOnly == true); } return(Success(x)); }
public void HandleBxEvent() { /// Bitrix Event Handles FORM Type parameters /// Request.Form[data[FIELDS_AFTER]] /// Request.Form[data[FIELDS_AFTER][ID]] /// Request.Form[auth[user_id]] /// etc... see documentation var form = HttpContext.Request.Form; var emailTo = ""; var emailSubject = ""; var emailText = ""; var taskId = "0"; if (form == null || form.Count == 0) return; var ev = form["event"]; switch (ev) { case "ONTASKADD": emailSubject = "ახალი ამოცანა"; emailText = "პორტალზე დაემატა ახალი ამოცანა <a href='https://crm.ants.ge/Tasks/" + form["data[FIELDS_AFTER][ID]"] + "'> ID: " + form["data[FIELDS_AFTER][ID]"] + "</a>"; taskId = form["data[FIELDS_AFTER][ID]"]; break; case "ONTASKCOMMENTADD": emailSubject = "ახალი კომენტარი"; emailText = "ამოცანას დაემატა კომენტარი. იხილეთ ამოცანა <a href='https://crm.ants.ge/Tasks/" + form["data[FIELDS_AFTER][TASK_ID]"] + "'> ID: " + form["data[FIELDS_AFTER][TASK_ID]"] + "</a>"; taskId = form["data[FIELDS_AFTER][TASK_ID]"]; break; } if (taskId == "0") throw new Exception("No Task ID"); var http = new HttpClient(); var bx = new BXManager(); var responseMessage = http.GetAsync(bx.bxRestWebHookUrl + "tasks.task.get?taskId=" + taskId).Result; JsonDocument json = null; if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK) { var response = responseMessage.Content.ReadAsStringAsync(); json = JsonDocument.Parse(response.Result); } var responsibleId = Convert.ToInt32(json.RootElement.GetProperty("result").GetProperty("task").GetProperty("responsibleId").ToString()); var pkg = new PKG_USERS(); var user = pkg.GetUser(responsibleId); emailTo = user.email; if (emailTo.Trim().Length == 0) throw new Exception("No emailTo Found"); new EmailService().SendEmail(emailTo, emailSubject, emailText); }
public JsonDocument DeleteBxUser([FromBody] newBxUser newBxUser) { if (!authUser.is_admin) { return(throwError("თქვენ არ გაქვთ ამ ოპერაციის განხორციელების უფლება")); } if (newBxUser.antsUserID > 0) { var x = new PKG_USERS().deleteBxUser(newBxUser.antsUserID, authUser.ID); return(Success(x)); } else { return(throwError("შეავსეთ მეილის(Ants UserID) ველი")); } }
public JsonDocument Register([FromBody] UserRegistration user) { var users = new PKG_USERS(); var register = users.Register(user.email, user.password, user.fullName, user.phone); if (register) { var email = new EmailService(); email.SendEmail(user.email, "რეგისტრაცია Ants.ge ზე", "თქვენ წარმატებით დარეგისტრირდით Ants.ge პორტალზე."); return(this.Authenticate(user)); } else { return(throwError("ელ.ფოსტა უკვე რეგისტრირებულია.")); } }
public JsonDocument ProjectDoneFreelancer([FromBody] tbProjects project) { project.workerUserId = authUser.ID; if (project.ID > 0) { project = _pkg_project.ProjectDoneFreelancer(project); var ownerEmail = new PKG_USERS().getUserEmail(project.userId); var projectDetailsHtml = project.name + "<br />" + project.ID + "<br />" + project.description + "<br />" + project.category + "<br />" + project.type + "<br />" + project.budget; var email = new EmailService(); email.SendEmail(ownerEmail, "პროექტის დასრულების მოთხოვნა - ID: " + project.ID, projectDetailsHtml); return(Success()); } else { return(throwError("პროექტი არ მოიძებნა")); } }
public JsonDocument Register([FromBody] Registration user) { var users = new PKG_USERS(); var register = users.Register(user.email, user.password, user.fullName, user.phone, user.tin, user.samformaType, user.userType); if (register) { var email = new EmailService(); email.SendEmail(user.email, "რეგისტრაცია {{საიტი}} ზე", "თქვენ წარმატებით დარეგისტრირდით {{საიტი}} პორტალზე."); LoginCredentials login = new LoginCredentials(); login.email = user.email; login.password = user.password; return(this.Authenticate(login)); } else { return(throwError("ელ.ფოსტა უკვე რეგისტრირებულია.")); } }
public JsonDocument ProjectDoneOwner([FromBody] tbProjects project) { project.userId = authUser.ID; if (project.ID > 0) { project = _pkg_project.ProjectDoneOwner(project); var email = new EmailService(); var projectDetailsHtml = project.name + "<br />" + project.ID + "<br />" + project.description + "<br />" + project.category + "<br />" + project.type + "<br />" + project.budget; var users = new PKG_USERS(); var workerEmail = users.getUserEmail(Convert.ToInt32(project.workerUserId)); var ownerEmail = users.getUserEmail(Convert.ToInt32(project.userId)); email.SendEmail(workerEmail, "cloudwork.ge - პროექტი დასრულდა", projectDetailsHtml); email.SendEmail(ownerEmail, "cloudwork.ge - პროექტი დასრულდა", projectDetailsHtml); return(Success()); } else { return(throwError("პროექტი არ მოიძებნა")); } }
//JsonElement public JsonDocument Authenticate([FromBody] LoginCredentials user) { if (user.email == null || user.password == null) { throwError("შეიყვანეთ მონაცემები"); } var method = new PKG_USERS(); //AuthUser authUser = null; try { authUser = new TokenManager().getAuthUserByToken(null, HttpContext); } catch (Exception ex) { } // if anyone is logged in if (authUser != null) { return(throwError("You are already logged in as " + authUser)); } AuthUser auth = null; //if no one is logged in, Authenticate if (method.Authenticate(user.email.ToString(), user.password.ToString(), out auth)) { authUser = auth; authUser.token = new TokenManager().createSetToken(authUser); var dict = new Dictionary <string, object>(); dict.Add("access_token", authUser.token); return(Success(dict)); } else { return(throwError("ელ.ფოსტა ან პაროლი არასწორია")); } }
//JsonElement public JsonDocument Authenticate([FromBody] UserCredentials user) { var method = new PKG_USERS(); //AuthUser authUser = null; try { authUser = new TokenManager().getAuthUserByToken(null, HttpContext); } catch (Exception ex) { } // if anyone is logged in if (authUser != null) { return(throwError("You are already logged in as " + authUser)); } AuthUser auth = null; //if no one is logged in, Authenticate if (method.Authenticate(user.email.ToString(), user.password.ToString(), out auth)) { authUser = auth; try { authUser.user1C = new PKG_1C().get1CUser(authUser.ID); } catch (Exception ex) { } authUser.token = new TokenManager().createSetToken(authUser); var dict = new Dictionary <string, object>(); dict.Add("access_token", authUser.token); JsonDocument bxAuth = null; bxAuth = AuthBitrixFromAuthUser(authUser); // Auths bitrix user from authUser refreshtoken or email pass if (bxAuth == null) { return(Success(dict)); } JsonElement bxToken; JsonElement bxRefreshToken; bxAuth.RootElement.TryGetProperty("access_token", out bxToken); // Get Bitrix and your accesstoken together and return if (bxToken.ToString().Length > 0) { authUser.bx_access_token = bxToken.ToString(); } var bxData = new Dictionary <string, object>(); bxData.Add("access_token", bxToken); dict.Add("bx_data", bxData); return(Success(dict)); } else { return(throwError("ელ.ფოსტა ან პაროლი არასწორია")); } }
public UsersController() { provider = new PKG_USERS(); }
public JsonDocument GetUserModules() { var x = new PKG_USERS().GetUserModules(authUser.ID); return(Success(x)); }