コード例 #1
0
ファイル: ProfileViewModel.cs プロジェクト: ExaurovNM/Lemon
 public ProfileViewModel(Account user, bool isEditable,int userId, int positiveRaite, int negativeRaite, List<string> comments)
 {
     this.IsExist = user != null;
     this.IsEditable = isEditable;
     this.userId = userId;
     this.PositiveRaite = positiveRaite;
     this.NegativeRaite = negativeRaite;
     this.Comments = comments;
 }
コード例 #2
0
ファイル: AccountRepository.cs プロジェクト: ExaurovNM/Lemon
 public void Create(Account account)
 {
     using (var context = new DataBaseContext())
     {
         account.CreatedTime = DateTime.UtcNow;
         context.Accounts.Add(account);
         context.SaveChanges();
     }
 }
コード例 #3
0
ファイル: AuthService.cs プロジェクト: ExaurovNM/Lemon
        public void CreateAccount(string userName, string email, string password)
        {
            var existingAccount = accountRepository.GetByEmail(email);
            if (existingAccount != null)
            {
                throw new ArgumentException("Email is already used");
            }

            existingAccount = accountRepository.GetByUserName(userName);
            if (existingAccount != null)
            {
                throw new ArgumentException("UserName is already used");
            }

            var salt = Guid.NewGuid().ToString();
            var account = new Account
                {
                    UserName = userName,
                    PasswordHash = criptoProvider.ComputeHash(password, salt),
                    Email = email,
                    Salt = salt
                };
            accountRepository.Create(account);
        }
コード例 #4
0
ファイル: AuthService.cs プロジェクト: ExaurovNM/Lemon
        public void Logon(Account account, bool remember = false)
        {
            var serializeModel = new CustomPrincipalSerializeModel
                {
                    Email = account.UserName,
                    Id = account.Id
                };

            var serializer = new JavaScriptSerializer();

            var userData = serializer.Serialize(serializeModel);

            var authTicket = new FormsAuthenticationTicket(
                     1,
                     account.UserName,
                     DateTime.Now,
                     DateTime.Now.AddMinutes(60),
                     remember,
                     userData);

            var encTicket = FormsAuthentication.Encrypt(authTicket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }