public async Task <JsonResult> CreateNewUser(PegaUser user) { if (!ModelState.IsValid) { return(Json(ResultsItem.Error(ModelState.GetAllErrorsString()))); } if (!Regex.IsMatch(user.Username, @"^[a-zA-Z0-9_\-\.]+$")) { return(Json(ResultsItem.Error("Username must contain only: Letters(A-Z), Numbers(0-9), _, -, or ."))); } if (!Utilities.IsValidEmailAddress(user.Email)) { return(Json("Please enter a valid email address.")); } var createPair = await AuthorizationLogic.CreateNewUser(user); if (createPair.Result.IsSuccess) { SetSession(Constant.Session.SessionCurrentUser, createPair.Value); TempData["UserCreatedTransferMessage"] = createPair.Result.Message; return(Json(ResultsItem.Success("Success"))); } return(Json(ResultsItem.Error(createPair.Result.Message))); }
public async Task <JsonResult> CurrentUserChangePassword(PegaUser user) { if (user.NewChangedPassword.Length < 8 || user.NewChangedPassword.Length > 30) { return(Json(ResultsItem.Error("Password changed failed: Password length must be from 8 - 30 characters."))); } if (user.NewChangedPassword != user.ConfirmNewChangedPassword) { return(Json(ResultsItem.Error("Passwords does not match."))); } if (CurrentUser.Username != user.Username) { return(Json(ResultsItem.Error("Username does not match."))); } // do-later: check if current pw is valid first. if (!AuthorizationLogic.AuthorizeUser(CurrentUser.Username, user.Password)) // Change password var pwChangeResult = await AuthorizationLogic.ChangePassword(user.Username, user.NewChangedPassword); if (!pwChangeResult.IsSuccess) { return(Json(pwChangeResult)); } HttpContext.Session.Clear(); string successMessage = "Your password has been successfully reset. Please login again"; TempData["message"] = successMessage; return(Json(ResultsItem.Success(successMessage))); }
public static async Task <ResultsPair <Portfolio> > InsertNewPortfolio(PegaUser user, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault) { var validateRequest = IsValidDBRequest(user, 0); if (!validateRequest.IsSuccess) { return(ResultsPair.CreateError <Portfolio>(validateRequest.Message)); } return(await CryptoRepository.InsertNewPortfolio(user.UserId, portfolioName, displayType, isDefault)); }
public static ResultsItem DeleteAPI(int apiId, PegaUser user) { var validateRequest = IsValidDBRequest(user, apiId, validateAPI: true); if (!validateRequest.IsSuccess) { return(validateRequest); } return(CryptoRepository.DeleteAPI(apiId)); }
public static ResultsItem InsertNewAPI(ExchangeApiInfo exchangeApiInfo, PegaUser user) { var validateRequest = IsValidDBRequest(user, 0); if (!validateRequest.IsSuccess) { return(validateRequest); } return(CryptoRepository.InsertNewAPI(exchangeApiInfo, user)); }
private static string GeneratePassword(Types.EncryptionType encryptionType, PegaUser user) { switch (encryptionType) { case Types.EncryptionType.ApiKey_Public: return($"QZ{string.Join("d", user.Username.Reverse())}_V638uhWV"); case Types.EncryptionType.ApiKey_Private: return($"TZ{user.Username}V638{string.Join("b", user.CreatedDate.ToShortDateString().Replace("/", "").Reverse())}_$WV"); } return(string.Empty); }
public static async Task <ResultsItem> UpdateUserCoinAsync(CryptoCoin coin, PegaUser user) { var validateRequest = IsValidDBRequest(user, coin.PortfolioId, validatePortfolio: true); if (!validateRequest.IsSuccess) { return(validateRequest); } return(await CryptoRepository.UpdateUserCoinAsync(coin)); }
public static PegaUser GetDevUser(string username) { if (AppSettingsProvider.IsDevelopment) { using (EntityFramework.PegasunDBContext db = new EntityFramework.PegasunDBContext()) { PegaUser user = db.Users.First(x => x.Username == username).Adapt <PegaUser>(); user.Portfolios = db.Portfolios.Where(x => x.UserId == user.UserId).Adapt <List <Layer.Models.Coins.Portfolio> >(); user.PTUserInfo = db.PTUserInfo.FirstOrDefault(x => x.UserId == user.UserId).Adapt <PTUserInfo>(); return(user); } } return(null); }
public void CreateUserTest() { ResultsItem deleteResult = AuthorizationLogic.DeletePegaUser("Test1234").Result; PegaUser user = new PegaUser { Username = "******", Password = "******", Email = "*****@*****.**", IsSubscribeNewsLetter = true }; ResultsPair <PegaUser> result = AuthorizationLogic.CreateNewUser(user).Result; Assert.IsTrue(result.Result.ResultType == Types.ResultsType.Successful); }
private static ResultsItem IsValidDBRequest(PegaUser user, int id, bool validateAPI = false, bool validatePortfolio = false, bool validateDemoUser = true) { if (validateDemoUser && user.Username.ToUpperInvariant() == "DEMOUSER") { return(ResultsItem.Error("DemoUser is not allowed to perform this action. Please login or create an account for free.")); } if (validatePortfolio && !user.HasPortfolio(id)) { return(ResultsItem.Error(Lang.PortfolioNotFound)); } if (validateAPI && !user.ExchangeApiList.Any(x => x.Id == id)) { return(ResultsItem.Error(Lang.ApiDeleteNotFound)); } return(ResultsItem.Success(string.Empty)); }
public static async Task <ResultsItem> DeletePortfolio(int portfolioId, PegaUser user) { var validateRequest = IsValidDBRequest(user, portfolioId, validatePortfolio: true); if (!validateRequest.IsSuccess) { return(validateRequest); } ResultsItem deleteResult = await CryptoRepository.DeletePortfolio(portfolioId); // Since we're deleting the only portfolio we have, create a new default one. if (user.Portfolios.Count == 1) { await InsertNewPortfolio(user, "Default", Types.PortfolioDisplayType.Private, true); } return(deleteResult); }
public async Task <JsonResult> Login(PegaUser user) { ModelState.Remove("Email"); if (!ModelState.IsValid) { return(Json(ResultsItem.Error(ModelState.GetAllErrorsString()))); } if (!Regex.IsMatch(user.Username, @"^[a-zA-Z0-9_\-\.@]+$")) { return(Json(ResultsItem.Error("Username must contain only: Letters(A-Z), Numbers(0-9), _, -, ., or an email address."))); } ResultsPair <PegaUser> pair = await AuthorizationLogic.AuthorizeUser(user.Username, user.Password); if (pair.Result.IsSuccess) { SetSession(Constant.Session.SessionCurrentUser, pair.Value); return(Json(ResultsItem.Success("Success"))); } return(Json(ResultsItem.Error(pair.Result.Message))); }
public static bool IsValidUser(this PegaUser user) => user != null && user.Username != "DemoUser";
public static async Task <ResultsItem> VoteBBComment(int commentId, bool isUpvote, PegaUser user) { return(await CommunityRepository.VoteBBComment(commentId, isUpvote, user)); }
public static async Task <ResultsPair <Portfolio> > ResetAllUserTrades(PegaUser user) { return(await CryptoRepository.ResetAllUserTrades(user)); }
public static async Task <ResultsItem> DeleteBBComment(int commentId, PegaUser user) { return(await CommunityRepository.DeleteBBComment(commentId, user)); }
public static async Task <ResultsItem> VoteBBThread(int threadId, bool isUpvote, PegaUser user) { return(await CommunityRepository.VoteBBThread(threadId, isUpvote, user)); }
public static async Task <CryptoCoin> GetSingleCoinByUser(long coinId, PegaUser user) { CryptoCoin coin = await CryptoRepository.GetSingleCoinByUser(coinId); return(!IsValidDBRequest(user, coin.PortfolioId, validatePortfolio: true, validateDemoUser: false).IsSuccess ? null : coin); }
public static async Task <ResultsItem> CreateBBComment(BBComment comment, PegaUser user) { return(await CommunityRepository.CreateBBComment(comment, user)); }
public static async Task <BBThread> GetThreadWithComments(int threadId, PegaUser user) { BBThread thread = await CommunityRepository.GetBBThreadWithComments(threadId, user); return(thread); }
public static async Task <ResultsItem> CreateBBThread(BBThread thread, PegaUser user) { return(await CommunityRepository.CreateBBThread(thread, user)); }
public static async Task <List <BBThread> > GetMessageThreads(int take, Types.ConvThreadCategory category, PegaUser user, int officialCoinId = 0) { return(await GetMessageThreads(take, new List <Types.ConvThreadCategory> { category }, user, officialCoinId)); }
public static async Task <List <BBThread> > GetMessageThreads(int take, List <Types.ConvThreadCategory> categories, PegaUser currentUser, int officialCoinId = 0) { List <BBThread> threads = await CommunityRepository.GetBBThreads(take, categories, currentUser, officialCoinId); return(threads); }
public static async Task <List <Portfolio> > GetAllUserPortfolioAsync(PegaUser user) { return(await CryptoRepository.GetAllUserPortfolioAsync(user)); }
public static async Task <ResultsItem> DeleteUserCoinsAsync(List <CryptoCoin> coins, PegaUser user) { if (coins.Any(x => !IsValidDBRequest(user, x.PortfolioId, validatePortfolio: true).IsSuccess)) { return(ResultsItem.Error(Lang.PortfolioNotFound)); } return(await CryptoRepository.DeleteUserCoinAsync(coins)); }
public static ResultsPair <Portfolio> UpdatePortfolio(int portfolioId, string portfolioName, Types.PortfolioDisplayType displayType, bool isDefault, PegaUser user) { if (!IsValidDBRequest(user, portfolioId, validatePortfolio: true).IsSuccess) { return(ResultsPair.CreateError <Portfolio>(Lang.PortfolioNotFound)); } return(CryptoRepository.UpdatePortfolio(portfolioId, portfolioName, displayType, isDefault)); }
public static async Task <ResultsItem> DeleteAllUserCoinByExchangeAsync(int portfolioId, Types.Exchanges exchange, PegaUser user) { var validateRequest = IsValidDBRequest(user, portfolioId, validatePortfolio: true); if (!validateRequest.IsSuccess) { return(validateRequest); } return(await CryptoRepository.DeleteAllUserCoinByExchangeAsync(portfolioId, exchange)); }
public static async Task <ResultsItem> DeleteBBThread(int threadId, PegaUser user) { return(await CommunityRepository.DeleteBBThread(threadId, user)); }
public static string Decrypt(string value, Types.EncryptionType encryptionType, PegaUser user) { SetProperSaltAndVector(encryptionType); switch (encryptionType) { case Types.EncryptionType.ApiKey_Public: return(Decrypt(value, GeneratePassword(encryptionType, user))); case Types.EncryptionType.ApiKey_Private: return(Decrypt(value, GeneratePassword(encryptionType, user))); } return(string.Empty); }
public static async Task <ResultsItem> InsertCoinsToUserPortfolioAsync(List <CryptoCoin> coins, PegaUser user, int?portfolioId = null) { // Validation: Do not allow symbol to end in -USD. if (coins.Any(x => x.Symbol.ToUpperInvariant().Contains("-USD"))) { if (coins.Count == 1) { return(ResultsItem.Error("The coin symbol must not end in -USD. It should be USD-. For example: USD-ETH, USD-XRP.")); } coins = coins.Where(x => !x.Symbol.ToUpperInvariant().Contains("-USD")).ToList(); } if (portfolioId != null) { coins.ForEach(x => x.PortfolioId = portfolioId.Value); } if (coins.Any(x => !IsValidDBRequest(user, x.PortfolioId, validatePortfolio: true).IsSuccess)) { return(ResultsItem.Error(Lang.PortfolioNotFound)); } return(await CryptoRepository.InsertCoinsToUserPortfolioAsync(coins)); }