public ActionResult Login(LoginCreds model) { System.Threading.Thread.Sleep(500); using (UserAccountDB userAccountDB = new UserAccountDB()) { List <UserAccount> user_dtls = userAccountDB.UserDetails.Where(w => w.Email == model.UserName).ToList(); if (user_dtls.Count() == 0) { dynamic errorMessage = new { param1 = "UserName", param2 = "User Name not found." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } if (user_dtls.Count() > 1) { dynamic errorMessage = new { param1 = "UserName", param2 = "Multiple users found for this account." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } if (user_dtls[0].PassWord != model.PassWord) { dynamic errorMessage = new { param1 = "PassWord", param2 = "Invalid password." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } dynamic successMessage = new { url = Url.Action("Index", "Home") }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(successMessage, JsonRequestBehavior.AllowGet)); } }
public ActionResult Login() { LoginCreds model = new LoginCreds() { UserName = "******" }; return(View(model)); }
// public TMP_Text countryTxt; TMP_Text can be used to desplay data from the json body public void fetchData() { string userEmail = userName.text; //pulls the user submitted text from text field string userPassword = password.text; //pulls the user submitted text from text field LoginCreds credentials = new LoginCreds(); credentials.email = userEmail; //sets the values of the serialized class credentials credentials.password = userPassword; //so that a JSON object can be sent as byte data StartCoroutine(LogIn(credentials)); }
public ActionResult Login(LoginCreds login) { ViewBag.Header1 = "Please Login to continue."; dynamic jsonMessage = null; if (ModelState.IsValid) { using (var userManager = HttpContext.GetOwinContext().GetUserManager <AppUserManager>()) { var authManager = HttpContext.GetOwinContext().Authentication; AppUser user = userManager.FindByEmail(login.UserName); if (user == null) { jsonMessage = new { param1 = "UserName", param2 = "User Name not found." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } if (!userManager.CheckPassword(user, login.PassWord)) { jsonMessage = new { param1 = "Password", param2 = "Invalid password." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } if (user.SecurityStamp == null) { userManager.UpdateSecurityStamp(user.Id); } var ident = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, ident); var urls = HttpUtility.ParseQueryString(Request.UrlReferrer.Query).GetValues("ReturnUrl"); if (urls != null) { jsonMessage = new { url = urls[0].ToString() }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } jsonMessage = new { url = Url.Action("Index", "Home") }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } } else { jsonMessage = new { param1 = "ModelState", param2 = "ModelState was not valid." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } }
public HttpResponseMessage PostLogin(LoginCreds creds) { PokeUser usr = db.PokeUsers.Find(creds.Username); if (usr == null) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } if (Crypto.VerifyHashedPassword(usr.PwdHash, creds.Password) == false) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } FormsAuthentication.SetAuthCookie(creds.Username.ToLower(), false); return(Request.CreateResponse(HttpStatusCode.OK, usr)); }
public async Task <IActionResult> UserAuth([FromBody] LoginCreds loginCred) { string _AuthToken, _Firstname; var user = await userManager.FindByNameAsync(loginCred.UserName); if (user != null && await userManager.CheckPasswordAsync(user, loginCred.Password)) { _AuthToken = _JwtAuthenticationManager.Authenticate(loginCred.UserName); _Firstname = this._dbcontext.Staffs.Where(_userName => _userName.Mobile.ToString() == loginCred.UserName).FirstOrDefault().FirstName; return(StatusCode(StatusCodes.Status200OK, new { AuthToken = _AuthToken, FirstName = _Firstname })); } return(Unauthorized()); }
public JsonResult Login([FromBody] LoginCreds loginCreds) { var account = _accountService.Find(loginCreds.Username, loginCreds.Password); if (account != null) { return(new JsonResult(new { status = 200, account = new { _id = account._id, username = account.username, email = account.email, currency = account.currency, cart = account.cart } })); } else { return(new JsonResult(new { status = 404 })); } }
IEnumerator LogIn(LoginCreds credentials) { string URL = hostURL.text; //this is the rest api address pulled from the text field string jsonData = JsonUtility.ToJson(credentials); //this turns the class into a json string using (UnityWebRequest restAPI = UnityWebRequest.Put(URL + "/users/logIn", jsonData)) { restAPI.method = UnityWebRequest.kHttpVerbPOST; //this is declaring that we are actually sending a POST not a PUT, this is a little hack as above we declared it a PUT restAPI.SetRequestHeader("content-type", "application/json"); restAPI.SetRequestHeader("Accept", "application/json"); yield return(restAPI.SendWebRequest()); //sends out the request and waits for the returned content. if (restAPI.isNetworkError || restAPI.isHttpError) //checks for errors { Debug.Log(restAPI.error); } else { Debug.Log("Form upload complete!"); if (restAPI.isDone) { JSONNode returnedBody = JSON.Parse(System.Text.Encoding.UTF8.GetString(restAPI.downloadHandler.data)); if (returnedBody == null) { Debug.Log("failed log in"); } else { Debug.Log(returnedBody);//this DISPLAYS the json body to send to the api. } } } } }
public ActionResult Login() { if (Request.UrlReferrer == null) { ViewBag.Header1 = "Please Login to continue."; } else { var urls = HttpUtility.ParseQueryString(Request.UrlReferrer.Query).GetValues("ReturnUrl"); if (urls != null) { ViewBag.Header1 = "Please Login to access that page."; } else { ViewBag.Header1 = "Please Login to continue."; } } LoginCreds model = new LoginCreds(); model.UserName = "******"; return(View(model)); }
public async Task <IActionResult> SignInUser(LoginCreds loginCreds) { IAmazonCognitoIdentityProvider provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), region); CognitoUserPool userPool = new CognitoUserPool(poolId, appClientId, provider); CognitoUser user = new CognitoUser(loginCreds.Email, appClientId, userPool, provider); InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest() { Password = loginCreds.Password }; AuthFlowResponse authResponse = null; try { //Authenticate user and retrieve stripe Id authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false); GetUserRequest getUserRequest = new GetUserRequest(); getUserRequest.AccessToken = authResponse.AuthenticationResult.AccessToken; GetUserResponse getUser = await provider.GetUserAsync(getUserRequest); string email = getUser.UserAttributes.Where(a => a.Name == "email").First().Value; string stripeId = getUser.UserAttributes.Where(a => a.Name == "custom:stripeId").First().Value; //Retrieve plan type from stripe string userType = "Not registered as a Life Time Talents user"; StripeConfiguration.ApiKey = "sk_test_51GxEfiHhYK7K9XttqUpv12yjajZLs01TY95VhvzVfPEb5Ed8GaF3GFUV2iuhFZGkBgHoNib4iHBDlpALqWPplth6008EdMnnaw"; var service = new CustomerService(); Customer customer = service.Get(stripeId); var subscriptions = customer.Subscriptions; for (int i = 0; i < subscriptions.Count(); i++) { if (subscriptions.ElementAt(i).Plan.Id.Equals(standardPlan)) { userType = "Standard user"; } else if (subscriptions.ElementAt(i).Plan.Id.Equals(premiumPlan)) { userType = "Premium user"; } } Console.WriteLine(userType); if (userType == "Standard user") { await UpdateUserLastAccessed(loginCreds.Email, "Logged In"); return(Redirect("/Home/Main/" + email + "/" + userType + "/" + stripeId)); } else if (userType == "Premium user") { await UpdateUserLastAccessed(loginCreds.Email, "Logged In"); return(Redirect("/Home/Main/" + email + "/" + userType + "/" + stripeId)); } else { return(Redirect("/?Msg=loginFailed")); } } catch (Exception ex) { Console.WriteLine("Login failed: " + ex.Message); return(Redirect("/?Msg=loginFailed")); } }