//Insert new player object to the database, if the username was valid after trying to sign up. public async void RegisterNewPlayer(string playerName, string pw) { try { player.Name = playerName; player.Password = PasswordHandler.Encrypt(pw, player.Name); await playerCollection.InsertOneAsync(player); hsCollection = player.ScoreCollection; } catch (Exception e) { Debug.LogWarning(e); } }
public ActionResult <Response> Post(User user) { try { User userFromDb = appDbContext.Users.FirstOrDefault(u => u.Email == user.Email); if (userFromDb != null) { return(new Response(user, 409, "Email already exists")); } user.Password = PasswordHandler.Encrypt(user.Password, "sblw-3hn8-sqoy19"); appDbContext.Users.Add(user); appDbContext.SaveChanges(); return(new Response(user, 200, "User Created Successfully")); } catch (Exception ex) { return(new Response(null, 404, ex.Message)); } }
public ActionResult <Response> Put(User user) { try { if (!string.IsNullOrEmpty(HttpContext.Session.GetString("is_login"))) { var userId = int.Parse(HttpContext.Session.GetString("userid")); User userFromDb = appDbContext.Users.Where(u => u.Id == userId).FirstOrDefault(); if (userFromDb != null) { userFromDb.Email = user.Email; userFromDb.Name = user.Name; user.Password = PasswordHandler.Encrypt(user.Password, "sblw-3hn8-sqoy19"); userFromDb.Password = user.Password; userFromDb.ContactNumber = user.ContactNumber; userFromDb.Unit = user.Unit; userFromDb.Street = user.Street; userFromDb.City = user.City; userFromDb.PostalCode = user.PostalCode; userFromDb.AccountType = userFromDb.AccountType; appDbContext.SaveChanges(); return(new Response(userFromDb)); } else { return(new Response(null, 404, "No Data Found for User")); } } else { return(new Response(null, 403, "Authentication Failure")); } } catch (Exception ex) { return(new Response(null, 404, ex.Message)); } }
public IActionResult Post(User user) { if (user.Email.Equals(null) || user.Password.Equals(null)) { return(BadRequest(new { message = "Email or password can not be empty" })); } User userFromDb = appDb.User.FirstOrDefault(u => u.Email == user.Email); if (userFromDb != null) { return(BadRequest(new { message = "Email already exists", user.Email })); } user.Password = PasswordHandler.Encrypt(user.Password, "sblw-3hn8-sqoy19"); string token = authService.Authenticate(user.Email); appDb.User.Add(user); //string token = authService.Authenticate(user.Email); appDb.SaveChanges(); user.Token = token; user.Password = null; return(Ok(user)); }