private async Task <PairValue <Mo_Result, UserAccount> > signin(Mo_User_SignIn model) { PairValue <Mo_Result, UserAccount> back = new PairValue <Mo_Result, UserAccount> { first = new Mo_Result() }; var req = await Server.get_account_secure(model.username, model.password, true); UserAccount uacc = req.first; if (uacc != null) { back.first.result = true; back.second = uacc; uacc.lastLoggedDate = DateTime.Now; // post time //todo: сохранить только определенные значения if (uacc.useCount++ == ulong.MaxValue - 1) { uacc.useCount = 1; Console.WriteLine("Use count is retrived for id: " + uacc.id); } //refresh UACC await Server.updateProperties(uacc, "lastLoggedDate", "useCount"); } else { back.first.result = false; back.first.message = req.second; } return(back); }
public static async Task <PairValue <UserAccount, string> > get_account_secure(string usernameOrMail, string password, bool checkPassword) { var builder = Builders <UserAccount> .Filter; var filter = builder.Empty; var result = new PairValue <UserAccount, string>(); usernameOrMail = usernameOrMail?.ToLower(); if ((validLogin(usernameOrMail))) { filter = builder.Eq("username", usernameOrMail); } else if (validMail(usernameOrMail, out MailAddress mail)) { filter = builder.Eq("mail", usernameOrMail); } else { result.second = "Invalid login"; return(result); } if (checkPassword && !validPassword(password)) { result.second = "Invalid password"; return(result); } result.first = await accounts.Find(filter).FirstOrDefaultAsync(); if (result.first != null) { if (checkPassword && result.first.password != password) { result.second = "Incorrect password"; result.first = null; return(result); } result.first.role = result.first.role ?? "User"; // replace a null value } else { result.second = "Account is not found"; } return(result); }
public static async Task <UserAccount> get_account(string loginOrEmail) { PairValue <UserAccount, string> result = await get_account_secure(loginOrEmail, null, false); return(result.first); }