} // End GetById public ActiveToken Create(ActiveToken activeToken, string userName, string currentToken, string SourceIdentifier) { // Validation if (string.IsNullOrWhiteSpace(userName)) { throw new ApplicationException("The username for the current active token can not be null or empty"); } if (string.IsNullOrWhiteSpace(currentToken)) { throw new ApplicationException("The current token can not be null or empty"); } //if (_context.Users.Any(x => x.Username == user.Username)) // throw new AppException("Username \"" + user.Username + "\" is already taken"); //byte[] passwordHash, passwordSalt; //CreatePasswordHash(password, out passwordHash, out passwordSalt); activeToken.UserName = userName; activeToken.CurrentToken = currentToken; activeToken.Status = true; activeToken.TokenDate = DateTime.Now; activeToken.SourceIdentifier = SourceIdentifier; // Hardcoded by now.... TODO: Fix this hardcoded value activeToken.TokenExpireDate = DateTime.Now.AddHours(24); _context.ActiveTokens.Add(activeToken); _context.SaveChanges(); return(activeToken); } // End Create
public void AddToken(User user, string token) { ActiveToken t = new ActiveToken { Token = token, UserId = user.Id }; _context.Add(t); _context.SaveChanges(); }
public static ActiveTokenViewModel ConvertToViewModel(ActiveToken dbModel) { var viewModel = new ActiveTokenViewModel { Id = dbModel.Id, UserName = dbModel.UserName, CurrentToken = dbModel.CurrentToken, TokenDate = dbModel.TokenDate, TokenExpireDate = dbModel.TokenExpireDate, SourceIdentifier = dbModel.SourceIdentifier, Status = dbModel.Status }; return(viewModel); }
} // End Create public ActiveToken Update(ActiveToken activeTokenParam, string currentToken = null, string SourceIdentifier = null) { var activeToken = _context.ActiveTokens.Find(activeTokenParam.Id); if (activeToken == null) { throw new ApplicationException("ActiveToken not found"); } if (activeTokenParam.CurrentToken != activeToken.CurrentToken) { // username has changed so check if the new username is already taken if (_context.ActiveTokens.Any(x => x.CurrentToken == activeTokenParam.CurrentToken)) { throw new ApplicationException("CurrentToken " + activeTokenParam.CurrentToken + " is already taken"); } } // Update user properties activeToken.CurrentToken = activeTokenParam.CurrentToken; activeToken.UserName = activeTokenParam.UserName; activeToken.TokenDate = new DateTime(); // Hardcoded by now.... TODO: Fix this hardcoded value activeToken.TokenExpireDate = DateTime.Now.AddHours(24); activeToken.SourceIdentifier = activeTokenParam.SourceIdentifier; // Update password if it was entered //if(!string.IsNullOrWhiteSpace(password)) //{ // byte[] passwordHash, passwordSalt; // CreatePasswordHash(password, out passwordHash, out passwordSalt); // user.PasswordHash = passwordHash; // user.PasswordSalt = passwordSalt; //} _context.ActiveTokens.Update(activeToken); _context.SaveChanges(); return(activeToken); } // End Update
public async Task <ActionResult <TokenResponse> > PostActiveToken(ActiveToken activeToken) { ////ActiveToken activeToken = new ActiveToken ////{ //// Otp = content ////}; _context.ActiveToken.Add(activeToken); await _context.SaveChangesAsync(); //Check Otp and return token TokenResponse tokenresponse = new TokenResponse(); tokenresponse.TokenValue = "memel"; tokenresponse.ResponseCode = "00"; tokenresponse.ResponseMsg = "OK"; return(tokenresponse); //return CreatedAtAction("GetActiveToken", new { id = activeToken.Id }, activeToken); }
public User GetUserFromToken(string token) { var t = new JwtSecurityTokenHandler().ReadJwtToken(token); if (t.ValidTo > DateTime.Now) { ActiveToken dbToken = _context.ActiveTokens.Where(i => i.Token == token).FirstOrDefault(); if (dbToken == null) { return(null); } else { return(_context.Users.Where(i => i.Id == dbToken.UserId).FirstOrDefault()); } } else { return(null); } }
public async Task CreateToken(ActiveToken token) { await _context.ActiveToken.AddAsync(token); await _context.SaveChangesAsync(); }
public static System.Net.Http.HttpClient AddActiveToken(this System.Net.Http.HttpClient client) { client.DefaultRequestHeaders.Add("AuthorizeToken", ActiveToken.ToString()); return(client); }
public void MoveActiveToken() { ActiveToken.MoveSpaces(dice.Result); }
public bool IsAuthenticated() { return(ActiveToken.IsActive()); }