protected override Task <RequestStatus> HandleCommand(SignUpCommand request, CancellationToken cancellationToken) { var existing = _userAuthenticationDataRepository.FindUserAuth(request.Username); if (existing != null) { throw new UsernameConflictException($"User {request.Username} already exists"); } var user = new User(); user.Register(request.Username); var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED); var userAuth = new UserAuthenticationData() { Password = request.Password, UserId = user.UserIdentity.UserId, UserName = user.UserIdentity.UserName, Email = request.Email }; _userAuthenticationDataRepository.AddUserAuth(userAuth); _userRepository.AddUser(user); _eventBusService.Publish(user.PendingEvents, response.CorrelationId, request); user.MarkPendingEventsAsHandled(); return(Task.FromResult(response)); }
// ---------[ MENU OPTIONS ]--------- /// <summary>Opens the user's menu profile in a web browser.</summary> public void OpenProfileInBrowser() { UserAuthenticationData userData = UserAuthenticationData.instance; if (userData.userId != UserProfile.NULL_ID) { this.viewProfileButton.interactable = false; ModManager.GetAuthenticatedUserProfile( (p) => { if (this != null && p != null && userData.userId == p.id) { string profileURL = p.profileURL + @"/edit"; if (!string.IsNullOrEmpty(userData.steamTicket)) { profileURL += "?ref=steam"; } Application.OpenURL(profileURL); this.viewProfileButton.interactable = true; } }, (e) => { this.viewProfileButton.interactable = true; }); } }
// ---------[ EVENTS ]--------- private void OnButtonClick() { UserAuthenticationData userData = UserAuthenticationData.instance; bool loggedIn = !(userData.Equals(UserAuthenticationData.NONE)); bool isExternallyAuthenticated = (loggedIn && !(string.IsNullOrEmpty(userData.steamTicket) && string.IsNullOrEmpty(userData.gogTicket))); if (!loggedIn) { if (onLoggedOutClick != null) { onLoggedOutClick.Invoke(); } } else if (!isExternallyAuthenticated) { if (onModioAccountClick != null) { onModioAccountClick.Invoke(); } } else { if (onExternalAccountClick != null) { onExternalAccountClick.Invoke(); } } }
public void Show() { var authenticationData = new UserAuthenticationData(); Console.WriteLine("Введите почтовый адрес:"); authenticationData.Email = Console.ReadLine(); Console.WriteLine("Введите пароль:"); authenticationData.Password = Console.ReadLine(); try { var user = this.userService.Authenticate(authenticationData); SuccessMessage.Show("Вы успешно вошли в социальную сеть!"); SuccessMessage.Show("Добро пожаловать " + user.FirstName); Program.userMenuView.Show(user); } catch (WrongPasswordException) { AlertMessage.Show("Пароль не корректный!"); } catch (UserNotFoundException) { AlertMessage.Show("Пользователь не найден!"); } }
public static UserAuthenticationData CreateUserAuthentication(string name, DateTime bd, out string origPw) { UserAuthenticationData userdata = new UserAuthenticationData(); try { string guidUsername = string.Format("{0}{1}{2}", name?.Replace(" ", ""), bd.Year, new Random(bd.Day).Next(99)); userdata.Username = "******"; userdata.Password = Guid.NewGuid().ToString().Replace("-", "").Substring(26); origPw = userdata.Password; string jsonSend = JsonConverter.serializeData <UserAuthenticationData>(userdata); string jsonAnswer = HttpConnectionController.Instance.CreateUser(jsonSend); userdata = JsonConverter.deserializeData <UserAuthenticationData>(jsonAnswer); userdata.Username = guidUsername; //TOTO_ check username //userdata = new UserAuthenticationData //( // guidUsername, // MD5Hash.Compute(guidPassword) //); } catch (Exception) { throw; } return(userdata); }
public bool Login(LoginData loginData) { LoginRequest request = new LoginRequest { UserName = loginData.UserName, Password = loginData.Password }; LoginResponse response = _client.Login(request); if (response.Success) { UserAuthenticationData userAuthentication = Mapper.Map <UserAuthenticationData>(response.User); if (response.PortfolioDatas != null) { userAuthentication.PortfolioData = response.PortfolioDatas; } SessionHelper.SetToSession(SessionKeyHolder.UserAuthorizationDataKey, userAuthentication); return(true); } return(false); }
// ---------[ EVENTS ]--------- /// <summary>Shows the menu.</summary> public void ShowMenu() { UserAuthenticationData userData = UserAuthenticationData.instance; bool loggedIn = !(userData.Equals(UserAuthenticationData.NONE)); this.loggedUser.gameObject.SetActive(loggedIn); this.logoutButton.gameObject.SetActive(loggedIn); this.loginButton.gameObject.SetActive(!loggedIn); this.viewProfileButton.gameObject.SetActive(loggedIn); this.dropdown.gameObject.SetActive(true); }
public User Authenticate(UserAuthenticationData userAuthenticationData) { var findUserEntity = userRepository.FindByEmail(userAuthenticationData.Email); if (findUserEntity is null) { throw new UserNotFoundException(); } if (findUserEntity.password != userAuthenticationData.Password) { throw new WrongPasswordException(); } return(ConstructUserModel(findUserEntity)); }
public SynchronizePortfolioResponse SynchronizePortfolio() { SynchronizePortfolioRequest request = new SynchronizePortfolioRequest { UserNr = _accountFacade.GetUserAuthenticationData().UserNr }; SynchronizePortfolioResponse response = _client.SynchronizePortfolio(request); UserAuthenticationData userData = _accountFacade.GetUserAuthenticationData(); userData.PortfolioData = response.PortfolioData; SessionHelper.SetToSession(SessionKeyHolder.UserAuthorizationDataKey, userData); return(response); }
public void UpdateUserAuth(UserAuthenticationData userAuthenticationData) { var sql = "UPDATE dbo.AuthData SET UserId = @UserId, Username = @Username, Password = @Password, Email = @Email WHERE UserId = @UserId"; using (var connection = new SqlConnection(_connectionSettings.ConnectionString)) { connection.Open(); var affected = connection.Execute(sql, new { Username = userAuthenticationData.UserName, Password = userAuthenticationData.Password, UserId = userAuthenticationData.UserId, Email = userAuthenticationData.Email }); if (affected <= 0) { throw new Exception(); } } }
public UserAuthenticationData AddUserAuth(UserAuthenticationData userAuthenticationData) { var sql = "INSERT INTO dbo.AuthData (UserId, Username, Password, Email) VALUES (@UserId, @Username, @Password, @Email)"; using (var connection = new SqlConnection(_connectionSettings.ConnectionString)) { connection.Open(); var affected = connection.Execute(sql, new { Username = userAuthenticationData.UserName, Password = userAuthenticationData.Password, UserId = userAuthenticationData.UserId, Email = userAuthenticationData.Email }); if (affected <= 0) { throw new Exception(); } return(userAuthenticationData); } }
//private static IRepository repository = null; #endregion #region methods /// <summary> /// Creates a customer and inserts it into the database. /// Creates the random username and password for the customer. /// </summary> /// <param name="companyName">name of the company </param> /// <param name="fullName">the full name of the customer e.g. Huber Thomas</param> /// <param name="birthDate">the birth date of the customer</param> /// <param name="adresse">the adresse of the customer e.g. 9500 Villach Italienerstraße 3</param> /// <returns>a copie of the customer</returns> public static Customer CreateCustomer(string companyName, string vorname, string nachname, DateTime birthDate, string adresse) { try { using (IRepository repository = RepositoryFactory.Instance.CreateRepository <Repository>()) { string origPw = string.Empty; UserAuthenticationData user = UserdataGenerator.CreateUserAuthentication(vorname + nachname, birthDate, out origPw); Customer customer = new Customer() { CustomerId = repository.Max <Customer, int>("CustomerId") + 1, Adress = adresse, WerkstattKonzern = DEFAULTWERKSTATTKONZERN, FirstName = vorname, LastName = nachname, BirthDate = birthDate, Username = user.Username, Password = user.Password }; repository.SaveOrUpdate(customer); Customer copy = customer.Clone() as Customer; copy.Password = origPw; return(copy); } } catch (DatabaseException) { throw; } catch (Exception ex) { throw (new DatabaseException(ex, "Error in creating customer!")); } }
protected virtual void OnGUI() { EditorGUILayout.LabelField("LOG IN TO/REGISTER YOUR MOD.IO ACCOUNT"); using (new EditorGUI.DisabledScope(isAwaitingServerResponse || isLoggedIn)) { EditorGUILayout.BeginHorizontal(); { using (new EditorGUI.DisabledScope(isInputtingEmail)) { if (GUILayout.Button("Email")) { isInputtingEmail = true; } } using (new EditorGUI.DisabledScope(!isInputtingEmail)) { if (GUILayout.Button("Security Code")) { isInputtingEmail = false; } } } EditorGUILayout.EndHorizontal(); if (isInputtingEmail) { emailAddressInput = EditorGUILayout.TextField("Email Address", emailAddressInput); } else { securityCodeInput = EditorGUILayout.TextField("Security Code", securityCodeInput); } EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Submit")) { isAwaitingServerResponse = true; GUIUtility.keyboardControl = 0; Action <string, MessageType> endRequestSendingAndInputEmail = (m, t) => { isAwaitingServerResponse = false; isInputtingEmail = true; helpMessage = m; helpType = t; Repaint(); }; Action <string, MessageType> endRequestSendingAndInputCode = (m, t) => { isAwaitingServerResponse = false; isInputtingEmail = false; helpMessage = m; helpType = t; Repaint(); }; if (isInputtingEmail) { securityCodeInput = ""; APIClient.SendSecurityCode(emailAddressInput, m => endRequestSendingAndInputCode(m.message, MessageType.Info), e => endRequestSendingAndInputEmail(ConvertErrorToHelpString(e), MessageType.Error)); } else { Action <UserProfile, string> onGetUserProfile = (userProfile, token) => { UserAuthenticationData userData = new UserAuthenticationData() { userId = userProfile.id, token = token, }; UserAuthenticationData.instance = userData; helpMessage = ("Welcome " + userProfile.username + "! You have successfully logged in." + " Feel free to close this window."); isLoggedIn = true; LoginWindow.isAwaitingServerResponse = false; Repaint(); if (userLoggedIn != null) { userLoggedIn(userProfile); } }; Action <string> onTokenReceived = (token) => { UserAuthenticationData.instance = new UserAuthenticationData() { userId = UserProfile.NULL_ID, token = token, }; APIClient.GetAuthenticatedUser((u) => onGetUserProfile(u, token), e => { UserAuthenticationData.instance = UserAuthenticationData.NONE; endRequestSendingAndInputCode(ConvertErrorToHelpString(e), MessageType.Error); }); }; APIClient.GetOAuthToken(securityCodeInput, onTokenReceived, e => endRequestSendingAndInputCode(ConvertErrorToHelpString(e), MessageType.Error)); } } } EditorGUILayout.EndHorizontal(); } if (!String.IsNullOrEmpty(helpMessage)) { EditorGUILayout.HelpBox(helpMessage, helpType); } }
static void Main(string[] args) { Console.WriteLine("Добро пожаловать в социальную сеть."); while (true) { Console.WriteLine("Войти в профиль (нажмите 1)"); Console.WriteLine("Зарегистрироваться (нажмите 2)"); switch (Console.ReadLine()) { case "1": { var authenticationData = new UserAuthenticationData(); Console.WriteLine("Введите почтовый адрес:"); authenticationData.Email = Console.ReadLine(); Console.WriteLine("Введите пароль:"); authenticationData.Password = Console.ReadLine(); try { User user = userService.Authenticate(authenticationData); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Вы успешно вошли в социальную сеть! Добро пожаловать {0}", user.FirstName); Console.ForegroundColor = ConsoleColor.White; while (true) { Console.WriteLine("Просмотреть информацию о моём профиле (нажмите 1)"); Console.WriteLine("Редактировать мой профиль (нажмите 2)"); Console.WriteLine("Добавить в друзья (нажмите 3)"); Console.WriteLine("Написать сообщение (нажмите 4)"); Console.WriteLine("Выйти из профиля (нажмите 5)"); switch (Console.ReadLine()) { case "1": { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Информация о моем профиле"); Console.WriteLine("Мой идентификатор: {0}", user.Id); Console.WriteLine("Меня зовут: {0}", user.FirstName); Console.WriteLine("Моя фамилия: {0}", user.LastName); Console.WriteLine("Мой пароль: {0}", user.Password); Console.WriteLine("Мой почтовый адрес: {0}", user.Email); Console.WriteLine("Ссылка на моё фото: {0}", user.Photo); Console.WriteLine("Мой любимый фильм: {0}", user.FavoriteMovie); Console.WriteLine("Моя любимая книга: {0}", user.FavoriteBook); Console.ForegroundColor = ConsoleColor.White; break; } case "2": { Console.Write("Меня зовут:"); user.FirstName = Console.ReadLine(); Console.Write("Моя фамилия:"); user.LastName = Console.ReadLine(); Console.Write("Ссылка на моё фото:"); user.Photo = Console.ReadLine(); Console.Write("Мой любимый фильм:"); user.FavoriteMovie = Console.ReadLine(); Console.Write("Моя любимая книга:"); user.FavoriteBook = Console.ReadLine(); userService.Update(user); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Ваш профиль успешно обновлён!"); Console.ForegroundColor = ConsoleColor.White; break; } } } } catch (WrongPasswordException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Пароль не корректный!"); Console.ForegroundColor = ConsoleColor.White; } catch (UserNotFoundException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Пользователь не найден!"); Console.ForegroundColor = ConsoleColor.White; } break; } case "2": { var userRegistrationData = new UserRegistrationData(); Console.WriteLine("Для создания нового профиля введите ваше имя:"); userRegistrationData.FirstName = Console.ReadLine(); Console.Write("Ваша фамилия:"); userRegistrationData.LastName = Console.ReadLine(); Console.Write("Пароль:"); userRegistrationData.Password = Console.ReadLine(); Console.Write("Почтовый адрес:"); userRegistrationData.Email = Console.ReadLine(); try { userService.Register(userRegistrationData); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Ваш профиль успешно создан. Теперь Вы можете войти в систему под своими учетными данными."); Console.ForegroundColor = ConsoleColor.White; } catch (ArgumentNullException) { Console.WriteLine("Введите корректное значение."); } catch (Exception) { Console.WriteLine("Произошла ошибка при регистрации."); } break; } } } }
public static System.Tuple <Model.AuthUser, bool> IsAuthenticateUser(string loginId, string loginPassword) { return(UserAuthenticationData.GetAuthenticatedUser(loginId, loginPassword)); }