public Responses.ErrorResponse Remove(String code = null) { EmailValidationCode request = EmailValidationCode.Get(EmailValidationType.Remove, this); if (code != null && (request == null || !code.EqualsCharArray(request.Code))) return new Responses.ErrorResponse("incorrect removal code"); if (request != null) request.Remove(); DatabaseManager.Delete(this); return null; }
public static Responses.ErrorResponse AttemptLogin(String username, String passwordHash, out AuthSession session) { session = null; if (username == null || username.Length == 0) { return new Responses.ErrorResponse("no username given"); } if (!Account.IsUsernameValid(username)) { return new Responses.ErrorResponse("invalid username or password"); } if (passwordHash != null && passwordHash.Length > 0) { if (!Account.IsPasswordHashValid(passwordHash)) { return new Responses.ErrorResponse("invalid username or password"); } } else { return new Responses.ErrorResponse("auth error: no password given"); } var account = DatabaseManager.SelectFirst<Account>(x => x.Username == username); if (account == null || !passwordHash.EqualsCharArray(account.PasswordHash)) { return new Responses.ErrorResponse("invalid username or password"); } session = AuthSession.Get(account); if (session == null || session.IsExpired) session = AuthSession.Create(account); return null; }
public Responses.ErrorResponse Activate(String code = null) { if (IsVerified) return new Responses.ErrorResponse("account already activated"); EmailValidationCode request = EmailValidationCode.Get(EmailValidationType.Activate, this); if (code != null && (request == null || !code.EqualsCharArray(request.Code))) return new Responses.ErrorResponse("incorrect activation code"); if (request != null) request.Remove(); if (_sOwnerEmails.Exists(x => x == Email)) { Rank = Rank.Owner; } else { Rank = Rank.Verified; } var ply = Player.GetPlayer(this); ply.Balance = 10; DatabaseManager.Update(this); DatabaseManager.Update(ply); return null; }
public static Responses.ErrorResponse AttemptGet(EmailValidationType type, String email, String code, out EmailValidationCode valid, out Account account) { valid = null; account = null; if (email == null || email.Length == 0) return new Responses.ErrorResponse("no email address given"); if (!Account.IsEmailValid(email)) return new Responses.ErrorResponse("invalid email address"); if (code == null || code.Length == 0) return new Responses.ErrorResponse("no validation code given"); if (!Account.IsPasswordHashValid(code)) return new Responses.ErrorResponse("invalid validation code"); account = DatabaseManager.SelectFirst<Account>(x => x.Email == email); if (account == null) return new Responses.ErrorResponse("invalid email address"); valid = EmailValidationCode.Get(type, account); if (valid == null || !code.EqualsCharArray(valid.Code)) { valid = null; return new Responses.ErrorResponse("invalid validation code"); } if (valid.IsExpired) { valid = null; return new Responses.ErrorResponse("expired validation code"); } return null; }