DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CreateUserStatement.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 using Deveel.Data.Security;
22 
23 namespace Deveel.Data.Sql.Statements {
24  [Serializable]
25  public sealed class CreateUserStatement : SqlStatement, IPreparable {
26  public CreateUserStatement(string userName, SqlExpression password) {
27  if (password == null)
28  throw new ArgumentNullException("password");
29  if (String.IsNullOrEmpty(userName))
30  throw new ArgumentNullException("userName");
31 
32  UserName = userName;
33  Password = password;
34  }
35 
37  UserName = data.GetString("UserName");
38  Password = data.GetValue<SqlExpression>("Password");
39  }
40 
41  public string UserName { get; private set; }
42 
43  public SqlExpression Password { get; private set; }
44 
45  protected override void GetData(SerializeData data) {
46  data.SetValue("UserName", UserName);
47  data.SetValue("Password", Password);
48  }
49 
51  var preparedPassword = Password.Prepare(preparer);
52  return new CreateUserStatement(UserName, preparedPassword);
53  }
54 
55  protected override void ExecuteStatement(ExecutionContext context) {
56  var evaluated = Password.EvaluateToConstant(context.Request, null);
57  var passwordText = evaluated.AsVarChar().Value.ToString();
58 
59  context.Request.Query.CreateUser(UserName, passwordText);
60  }
61 
62  #region PreparedSerializer
63 
64  //internal class PreparedSerializer : ObjectBinarySerializer<CreateUserStatement> {
65  // public override void Serialize(CreateUserStatement obj, BinaryWriter writer) {
66  // writer.Write(obj.UserName);
67  // SqlExpression.Serialize(obj.Password, writer);
68  // }
69 
70  // public override CreateUserStatement Deserialize(BinaryReader reader) {
71  // var userName = reader.ReadString();
72  // var expression = SqlExpression.Deserialize(reader);
73 
74  // return new CreateUserStatement(userName, expression);
75  // }
76  //}
77 
78  #endregion
79  }
80 }
This is a plain-text password defined by the user.
void SetValue(string key, Type type, object value)
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
override void ExecuteStatement(ExecutionContext context)
An interface used to prepare a SqlExpression object.
override void GetData(SerializeData data)
CreateUserStatement(string userName, SqlExpression password)
object Prepare(IExpressionPreparer preparer)
Converts the underlying value of this instance into an object that can be evaluated by an expression...
Defines the base class for instances that represent SQL expression tree nodes.
A contract for objects that participate to a SqlExpression.Prepare phase of an expression evaluation...
Definition: IPreparable.cs:30