public ActionResult DeleteConfirmed(int id) { Models.Authorization authorization = db.Authorization.Find(id); db.Authorization.Remove(authorization); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id_Autorization,Login,Password")] Models.Authorization authorization) { if (ModelState.IsValid) { db.Entry(authorization).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authorization)); }
public override void OnAuthorization(AuthorizationContext filterContext) { // Do whatever checking you need here var auth = new Models.Authorization(); if (auth.Users.Count > 0) { filterContext.Result = new HttpUnauthorizedResult(); } }
public ActionResult Create([Bind(Include = "id_Autorization,Login,Password")] Models.Authorization authorization) { if (ModelState.IsValid) { db.Authorization.Add(authorization); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authorization)); }
public String getID(Models.Authorization auth, string name) { foreach (var accounts in auth.accounts) { if (accounts.name == "Radya Labs") { return(accounts.id); } } return(null); }
public async Task <IActionResult> Create([Bind("id,first_name,last_name,birth_date,profile_img,profile_background,gender,phone_number,email,password,reenter_password")] User user, IFormFile profile_img) { if (ModelState.IsValid) { if (user.password.Equals(user.reenter_password)) { var users = data.getConnection().GetCollection <User_Authorization>("User"); var check_user = users.Find(x => x.authorization.username == user.email).SingleAsync(); try { User_Authorization au = check_user.Result; return(BadRequest(new { Message = "Email is already existed" })); } catch (AggregateException ae) { } // specify that we want to randomly generate a 20-byte salt using (var deriveBytes = new Rfc2898DeriveBytes(user.password, 20)) { byte[] salt = deriveBytes.Salt; byte[] key = deriveBytes.GetBytes(20); // derive a 20-byte key Models.Authorization autho = new Models.Authorization { username = user.email, salt = salt, key = key }; user.created_date = DateTime.Now; user.last_login = DateTime.Now; if (profile_img != null) { var path = _env.WebRootPath; var uploads = Path.Combine(path, "img"); user.profile_img = "/img/" + save_fileAsync(uploads, profile_img); } else { user.profile_img = "/img/unknown.jpg"; } await users.InsertOneAsync(new User_Authorization { authorization = autho, user = user }); // save salt and key to database } return(Ok("Insert successfully")); } else { return(BadRequest(new { Message = "Password and Re-enter password must match" })); } } else { return(BadRequest(new { Message = "Please fill all fields" })); } }
// GET: Authorizations/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Authorization authorization = db.Authorization.Find(id); if (authorization == null) { return(HttpNotFound()); } return(View(authorization)); }
public async System.Threading.Tasks.Task <ActionResult> Index() { var code = Request.Params["code"]; string url = string.Format("https://launchpad.37signals.com/authorization/token?type=web_server&client_id=" + client_id + "&redirect_uri=" + redirectURI + "&client_secret=" + client_secret + "&code=" + code); var response = await client.PostAsync(url, null); var responseString = await response.Content.ReadAsStringAsync(); var ReturnedToken = JsonConvert.DeserializeObject <Token>(responseString); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ReturnedToken.access_token); var reqauth = await client.GetStringAsync(accountURL); Models.Authorization account_id = JsonConvert.DeserializeObject <Models.Authorization>(reqauth); var id = getID(account_id, "Radya Labs"); return(View()); }
public async Task <DiscordUser> GetUserAsync(Models.Authorization token) { using (var client = new HttpClient()) { var req = new HttpRequestMessage(HttpMethod.Get, $"{_apiEndpoint}/users/@me"); req.Headers.Add("authorization", $"{token.TokenType} {token.AccessToken}"); var res = await client.SendAsync(req); if (res.StatusCode != HttpStatusCode.OK) { return(null); } var contentString = await res.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <DiscordUser>(contentString)); } }