public void RegisterUser(object s, EventArgs e) { if (Page.IsValid) { var user = new Core.Entities.User { FirstName = FirstName.Text, LastName = LastName.Text, EmailAddress = EmailAddress.Text, Telephone = Telephone.Text, ClearPassword = PIN.Text, GenderId = (Core.Entities.Gender)Enum.ToObject(typeof(Core.Entities.Gender), int.Parse(Gender.SelectedValue)), DateOfBirth = DateTime.Parse(DateOfBirth.Text), Roles = new List <Core.Entities.Role> { Core.Entities.Role.User }, AuthToken = Guid.NewGuid().ToString(), StatusId = Core.Entities.UserStatus.Verified }; user.Save(); Master.DropCookie(user.AuthToken); Master.Feedback = "Your account has been created and you are now logged in."; Response.Redirect(Request.QueryString["r"] ?? DashboardUrl); } }
public ActionResult FacebookAuthenticationCallback() { FacebookOAuthResult facebookOAuthResult; if (!FacebookOAuthResult.TryParse(Request.Url, out facebookOAuthResult)) { return(Content("failed to retrieve a facebook oauth result.")); } if (!facebookOAuthResult.IsSuccess) { return(Content("failed to authenticate.")); } // Nice! Authenticated with Facebook AND we have the OAuth Token. // So lets extract any data and create this user account. Core.Entities.User user = AcceptFacebookOAuthToken(facebookOAuthResult); // Now FormsAuthenticate this user, if they are active. if (user == null || !user.IsActive) { // Failed to authenticate. // ToDo: proper error message and clean UI. return(Content("failed to authenticate - user is inactive.")); } _customFormsAuthentication.SignIn(user.Id, user.DisplayName, Response); return(RedirectToAction("Index", "Home", new { area = "" })); // If I don't provide the area .. I get boom-ski :~( }
public User Login(LoginRequest request) { Core.Entities.User user = this.VerifyPassword(request.Email, request.Password); User userProfile = _mapper.Map <User>(user); userProfile.Token = JwtTokenHelper.GenerateJSONWebToken(this._jwtIssuerOptions, userProfile.Id, userProfile.Email); return(userProfile); }
public string Authentication([Service] IUnitOfWork unitOfWork, LoginInput inputData) { Core.Entities.User user = unitOfWork.User.Authenticate(inputData.Email, inputData.Password); if (user != null) { return(unitOfWork.Token.CreateToken(user)); } return("Invalid username"); }
public Task Create(Core.Entities.User user) { var id = _users.Count + 1; user.Id = id; _users.Add(user); return(Task.FromResult(true)); }
public ActionResult RegisterUser(string id) { StudentContext db = new StudentContext(); var tokenObject = db.RegistrationTokens.Where(t => t.Token == id).FirstOrDefault(); StudentTracker.Core.Entities.User objUser = new Core.Entities.User(); objUser.OrganizationId = tokenObject.OrganizationId; objUser.MasterId = tokenObject.CreatedBy; objUser.RegistrationToken = id; return(View(objUser)); }
private async Task AddUserAsync(Message message) { var newUser = new Core.Entities.User { FirstName = message.From?.FirstName ?? "N/A", LastName = message.From?.LastName ?? "N/A", TelegramId = (int)message.Chat.Id }; await _userRepository.AddAsync(newUser); }
private Core.Entities.User VerifyPassword(string email, string password) { Core.Entities.User user = this._userRepository.GetUserByEmail(email); if (user == null) { throw new Exception("User not found"); } if (!EncryptionHelper.VerifyMd5Hash(password, user.Password)) { throw new Exception("Invalid Credentials"); } return(user); }
private async Task SendEmailConfirm(Core.Entities.User user, string password) { var content = new RegisterMailContent { Email = user.Email, UserName = user.UserName, Password = password, Code = await _userManager.GenerateEmailConfirmationTokenAsync(_mapper.Map <User>(user)) }; await _mailService.SendRegisterMail(content); _logger.LogInformation($"Send email for user='******' Code='{content.Code}'"); }
public UserModel(Core.Entities.User user) { id = user.Id; userName = user.UserName; firstName = user.FirstName; lastName = user.LastName; role = user.Role; registrationDate = user.RegistrationDate; state = user.State; photo = user.PhotoLink; hasCar = user.HasCar; email = user.Email; password = user.PasswordHash; }
private static LaunchDarkly.Client.User GetUser(Core.Entities.User user) { if (user == null) { return(LaunchDarkly.Client.User.WithKey("anonymous").AndAnonymous(true)); } else { var firstName = user.Name.Substring(0, user.Name.IndexOf(" ")); var lastName = user.Name.Substring(user.Name.IndexOf(" ")); return(LaunchDarkly.Client.User.WithKey(user.Email) .AndFirstName(firstName) .AndLastName(lastName)); } }
public Core.Entities.User ToUserEntity() { var user = new Core.Entities.User { Name = this.Name, Surname = this.Surname, Email = this.Email, Password = this.Password, Verified = this.Verified, Address = this.Adress, City = this.City, PostalCode = this.PostalCode }; return(user); }
/// <returns>Returns true on success, otherwise returns false</returns> public bool Update(Core.Entities.User user) { var item = Mapper.Map <User>(user); try { _context.User.Update(item); _context.Entry(item).Property(x => x.Created).IsModified = false; _context.SaveChanges(); return(true); } catch { return(false); } }
public string BuildToken(Core.Entities.User user) { var claims = new[] { new Claim(JwtRegisteredClaimNames.NameId, user.UserId.ToString()), new Claim(JwtRegisteredClaimNames.Email, user.Email), new Claim(JwtRegisteredClaimNames.UniqueName, user.Name.ToString()), new Claim(JwtRegisteredClaimNames.Actort, user.ProfileId.ToString()), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], claims: claims, expires: DateTime.Now.AddMinutes(10), signingCredentials: creds); return(new JwtSecurityTokenHandler().WriteToken(token)); }
/// <returns>Returns true on success, otherwise returns false</returns> public bool Add(Core.Entities.User user) { var item = Mapper.Map <User>(user); try { item.Homeworld = null; item.Specie = null; _context.User.Add(item); _context.SaveChanges(); return(true); } catch { return(false); } }
public async Task TestInMemoryCreate() { var userRepository = new UserMemoryRepository(); var createUser = new CreateUser(userRepository); var user = new Core.Entities.User { UserName = "******", Password = "******", FirstName = "administrator", LastName = "administrator" }; await createUser.CreateAsync(user); Assert.AreEqual(1, user.Id); }
public async Task <Unit> Handle(RegistrationCommandModel request, CancellationToken cancellationToken) { var employee = await employeesRepository.GetEmployeeAsync(request.EmployeeId); if (employee == null) { throw new ManagerException(ErrorsMessage.RegistrationErrorMessage); } encrypt.PasswordHash(request.Password, out var salt, out var passwordHash); Core.Entities.User user = new Core.Entities.User(request.UserName, request.Email, DateTime.Now, salt, passwordHash, request.EmployeeId, request.Role) { Employee = employee }; await userRepository.RegistrationAsync(user); if (await userRepository.UnitOfWork.SaveChangesAsync(default) < 1)
public Core.Entities.User ToUser() { var user = new Core.Entities.User { Id = id, UserName = userName, FirstName = firstName, LastName = lastName, Role = role, RegistrationDate = registrationDate, State = state, PhotoLink = photo, HasCar = hasCar, Email = email, PasswordHash = password }; return(user); }
public async Task TestDatabaseCreate() { var options = new DbContextOptionsBuilder <UserContext>() .UseInMemoryDatabase("Users") .Options; await using var context = new UserContext(options); var userRepository = new UserDatabaseRepository(context); var createUser = new CreateUser(userRepository); var user = new Core.Entities.User { UserName = "******", Password = "******", FirstName = "administrator", LastName = "administrator" }; await createUser.CreateAsync(user); Assert.AreEqual(1, user.Id); }
private async void Auth(Core.Entities.User user) { var claims = new List <Claim> { new(ClaimTypes.Name, user.Email), new("UserName", user.UserName), new("UserId", user.Id), new(ClaimTypes.Role, await GetUserRole(user.Id)) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { AllowRefresh = true }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); }
public async Task Create(Core.Entities.User user) { var newUser = _userContext.Users.Add(user); await _userContext.SaveChangesAsync(); }
public ActionResult RegisterUser(string id) { StudentContext db = new StudentContext(); var tokenObject = db.RegistrationTokens.Where(t => t.Token == id).FirstOrDefault(); StudentTracker.Core.Entities.User objUser = new Core.Entities.User(); objUser.OrganizationId = tokenObject.OrganizationId; objUser.MasterId = tokenObject.CreatedBy; objUser.RegistrationToken = id; return View(objUser); }
void btnSave_Click(object sender, EventArgs e) { try { CMS.Core.Entities.User user = new Core.Entities.User(); user.CreationDate = DateTime.Now; user.ID = 0; user.Email = txtEmail.Text; user.IsActive = chkIsActive.Checked; user.IsDeleted = false; user.LanguageID = CMSContext.LanguageID; user.Password = txtPassword.Text; user.PortalID = CMSContext.PortalID; UserManager.Add(user); BeginAddMode(); FillUsers(-1); upnlUser.Update(); } catch (Exception ex) { dvProblems.Visible = true; dvProblems.InnerText = ex.Message; upnlUser.Update(); } }
public bool StatisicsIsEnabled(Core.Entities.User user) { return(client.BoolVariation("statistics", GetUser(user), false)); }
public List <MIBObject> Get(RSU rsu, Core.Entities.User user, string OID) { List <MIBObject> mibObjects; try { IPEndPoint receiver = new IPEndPoint(rsu.IP, rsu.Port); int timeout = _managerSettings.Timeout; Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu); ReportMessage report = discovery.GetResponse(timeout, receiver); var auth = new SHA1AuthenticationProvider(new Lextm.SharpSnmpLib.OctetString(user.SNMPv3Auth)); var priv = new DESPrivacyProvider(new Lextm.SharpSnmpLib.OctetString(user.SNMPv3Priv), auth); GetRequestMessage request = new GetRequestMessage(VersionCode.V3 , Messenger.NextMessageId , Messenger.NextRequestId , new OctetString(user.UserName) , new OctetString(String.Empty) , new List <Variable> { new Variable(new ObjectIdentifier(OID)) } , priv , Messenger.MaxMessageSize , report); ISnmpMessage reply = request.GetResponse(timeout, receiver); // Need to send again (RFC 3414)??? if (reply is ReportMessage) { //throw new ReplyIsReportMessage(); request = new GetRequestMessage(VersionCode.V3 , Messenger.NextMessageId , Messenger.NextRequestId , new OctetString(user.UserName) , new OctetString(String.Empty) , new List <Variable> { new Variable(new ObjectIdentifier(OID)) } , priv , Messenger.MaxMessageSize , reply); reply = request.GetResponse(timeout, receiver); if (reply.Pdu().ErrorStatus.ToInt32() != 0) { throw new SnmpGetError(); } } else if (reply.Pdu().ErrorStatus.ToInt32() != 0) { throw new SnmpGetError(); } mibObjects = SNMPVariables2MIBObjects(reply.Pdu().Variables); return(mibObjects); } catch (Lextm.SharpSnmpLib.Messaging.TimeoutException ex) { mibObjects = new List <MIBObject>(); mibObjects.Add(new MIBObject("0", SnmpType.OctetString, "Timeout")); return(mibObjects); } }
public bool Set(RSU rsu, Core.Entities.User user, string OID, SnmpType type, string value) { IPEndPoint receiver = new IPEndPoint(rsu.IP, rsu.Port); int timeout = _managerSettings.Timeout; Discovery discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu); ReportMessage report = discovery.GetResponse(timeout, receiver); var auth = new SHA1AuthenticationProvider(new Lextm.SharpSnmpLib.OctetString(user.SNMPv3Auth)); var priv = new DESPrivacyProvider(new Lextm.SharpSnmpLib.OctetString(user.SNMPv3Priv), auth); ISnmpData data; try { data = ConvertStringValue2SnmpData(type, value); } catch (InvalidDataType invalidDataType) { throw invalidDataType; } catch (FormatException formatException) { throw formatException; } List <Variable> variables = new List <Variable>() { new Variable(new ObjectIdentifier(OID), data) }; SetRequestMessage request = new SetRequestMessage(VersionCode.V3 , Messenger.NextMessageId , Messenger.NextRequestId , new OctetString(user.UserName) , new OctetString(String.Empty) , variables , priv , Messenger.MaxMessageSize , report); ISnmpMessage reply = request.GetResponse(timeout, receiver); // Need to send again (RFC 3414) if (reply is ReportMessage) { //throw new ReplyIsReportMessage(); request = new SetRequestMessage(VersionCode.V3 , Messenger.NextMessageId , Messenger.NextRequestId , new OctetString(user.UserName) , new OctetString(String.Empty) , variables , priv , Messenger.MaxMessageSize , reply); reply = request.GetResponse(timeout, receiver); if (reply.Pdu().ErrorStatus.ToInt32() != 0) { throw new InvalidDataType(); } } else if (reply.Pdu().ErrorStatus.ToInt32() != 0) { throw new InvalidDataType(); } return(true); }