private List <ViewUserModel> DecodeData(List <UserApp> list) { List <ViewUserModel> user_list = new List <ViewUserModel>(); for (int i = 0; i < list.Count(); i++) { Cryptographer cryptographer = new Cryptographer().Create(list[i].Upassword); string firstName = cryptographer.Decode(list[i].FirstName); string lastName = cryptographer.Decode(list[i].LastName); long count_task = _context.BoardTasks.Where(b => b.IdOwner == list[i].Id).Count(); ViewUserModel userView = new ViewUserModel() { Id = list[i].Id, Name = firstName.First().ToString().ToUpper() + String.Join("", firstName.Skip(1)), LastName = lastName.First().ToString().ToUpper() + String.Join("", firstName.Skip(1)), DateRegister = list[i].DateApp, CountTask = count_task, Image = list[i].ImagePath }; user_list.Add(userView); } return(user_list); }
public async Task <IActionResult> ProfileEdit() { long iduser; try { iduser = GetUserId(); } catch { return(RedirectToAction("Signin", "Account")); } UserApp userApp = null; try { await Task.Run(() => { userApp = new UserUtils().GetUserById(_context, iduser); }); } catch (Exception) { return(NotFound()); } if (userApp != null) { Cryptographer cryptographer = new Cryptographer().Create(userApp.Upassword); string name = cryptographer.Decode(userApp.FirstName); string lastname = cryptographer.Decode(userApp.LastName); string email = cryptographer.Decode(userApp.Email); DateTime dateTime = userApp.DateApp; string imagePath; if (userApp.ImagePath == null) { imagePath = ""; } else { imagePath = userApp.ImagePath; } UserViewModel user = new UserViewModel { Id = userApp.Id, Name = name.First().ToString().ToUpper() + String.Join("", name.Skip(1)), LastName = lastname.First().ToString().ToUpper() + String.Join("", lastname.Skip(1)), Email = email, DateRegister = dateTime, ImagePath = imagePath }; return(View(user)); } return(View()); }
public IActionResult Index() { string key = HttpContext.Session.GetString("key"); if (key != null) { int role = (int)HttpContext.Session.GetInt32("role"); if (role != 2) { return(NotFound()); } } else { return(RedirectToAction("Signin", "Account")); } try { List <UserApp> listTmp = _context.UserApps.Select(u => u).ToList(); List <ViewUserModel> user_list = new List <ViewUserModel>(); for (int i = 0; i < listTmp.Count(); i++) { Cryptographer cryptographer = new Cryptographer().Create(listTmp[i].Upassword); string firstName = cryptographer.Decode(listTmp[i].FirstName); string lastName = cryptographer.Decode(listTmp[i].LastName); long count_task = _context.BoardTasks.Where(b => b.IdOwner == listTmp[i].Id).Count(); ViewUserModel userView = new ViewUserModel() { Id = listTmp[i].Id, Name = firstName.First().ToString().ToUpper() + String.Join("", firstName.Skip(1)), LastName = lastName.First().ToString().ToUpper() + String.Join("", firstName.Skip(1)), DateRegister = listTmp[i].DateApp, CountTask = count_task, Image = listTmp[i].ImagePath }; user_list.Add(userView); } return(View(user_list)); } catch (Exception) { throw new Exception(); } }
public void EncodeToDecode() { Cryptographer a = new Cryptographer(); string input = "Привет, меня зовут Антон! А как зовут тебя? Hello, my name is <Anton> 1.."; Assert.AreEqual(input, a.Decode(a.Encode(input)), true); }
private void SetUserSession(UserApp userApp, int role, Cryptographer cryptographer) // Session settings { string userId = "userId" + userApp.Id.ToString(); HttpContext.Session.SetString("key", userId); HttpContext.Session.SetInt32(userId, (int)userApp.Id); HttpContext.Session.SetInt32("role", role); string user_name = cryptographer.Decode(userApp.FirstName); HttpContext.Session.SetString("name", user_name); }
public async Task <JsonResult> SendEmailAsync(string textEmail, long?id) { try { var user = await _context.UserApps.SingleOrDefaultAsync(u => u.Id == id); Cryptographer cryptographer = new Cryptographer().Create(user.Upassword); string email = cryptographer.Decode(user.Email); EmailService emailService = new EmailService(); await emailService.SendEmailAsync(email, "Info", textEmail); var empty = new { }; return(Json(empty)); } catch (Exception) { throw new Exception(); } }
// GET: BoardTasks public async Task <IActionResult> Index() { long iduser; try { iduser = GetUserId(); } catch { return(RedirectToAction("Signin", "Account")); } UserApp userApp = null; try { await Task.Run(() => { userApp = new UserUtils().GetUserById(_context, iduser); }); } catch (Exception) { return(NotFound()); } if (userApp != null) { Cryptographer cryptographer = new Cryptographer().Create(userApp.Upassword); string name = cryptographer.Decode(userApp.FirstName); string email = cryptographer.Decode(userApp.Email); UserViewModel user = new UserViewModel(); user.Id = userApp.Id; user.Name = name.First().ToString().ToUpper() + String.Join("", name.Skip(1)); user.Email = email; user.ImagePath = userApp.ImagePath; IEnumerable <BoardTask> usertasks = null; try { await Task.Run(() => { usertasks = new BoardTaskUtils().GetUsersBoardTask(_context, userApp.Id); }); } catch (Exception) { return(NotFound()); } UserTaskViewModel userTaskView = new UserTaskViewModel { UserView = user, BoardTasks = usertasks }; return(View(userTaskView)); } else { return(NotFound()); } }
public async Task <IActionResult> Confirm(long?id) // View Confirm page { if (id == null) { return(NotFound()); } UserApp userApp = null; try { await Task.Run(() => { userApp = new UserUtils().GetUserById(_context, (long)id); }); } catch (Exception) { HttpContext.Session.SetString(ERROR, "The server was not found or was not accessible. Try later."); return(RedirectToAction("RegisterError", "Account")); } if (userApp != null) { Cryptographer cryptographer = new Cryptographer().Create(userApp.Upassword); string decodeEmail = cryptographer.Decode(userApp.Email); EmailResponce goodEmail = await new EmailService().ChekEmaileService(decodeEmail); switch (goodEmail.Success) { case 1: EmailService emailService = new EmailService(); var callbackUrl = Url.Action( "ConfirmEmail", "Account", new { Token = userApp.Id, Email = userApp.Email }, protocol: HttpContext.Request.Scheme); await emailService.SendEmailAsync(decodeEmail, "Confirm email", $"Подтвердите регистрацию, перейдя по ссылке: <a href='{callbackUrl}'>Confirm email</a>"); ViewBag.Name = goodEmail.EmailData.Item1; ViewBag.Href = goodEmail.EmailData.Item2; return(View()); case -1: HttpContext.Session.SetString(ERROR, "Mail is not correct."); return(RedirectToAction("RegisterError", "Account")); } } return(NotFound()); }